I am working on a store script and need to be able to access a SQL database. I heard the the grapevine you can do something with the http api but i dont know how to use it. Can you please tell me how to access a database.
Data Base help
Started by Goobster22, Dec 21 2013 07:20 PM
5 replies to this topic
#1
Posted 21 December 2013 - 07:20 PM
#2
Posted 21 December 2013 - 11:16 PM
Sure, databases can be access by 2 simple-ish ways. (not limiting this)
1. I find this to be the best but its personal choice. You can create a webpage that handles all the transfers and pulls itself. A page like this is doing all the database accessing! Your computer in game will simply be running a couple of HTTP functions calling the site. Generally they are GET variables.
Here is an example!
(not protected against SQL injection)
MySQLi would be more efficient.
Sorry, the 2nd way actually doesn't exists anymore (from what I am aware)
Maybe another user could clean this up for me. There was a mod that could be added to the game and would allow connect to MySQL databases. I am not sure sorry
1. I find this to be the best but its personal choice. You can create a webpage that handles all the transfers and pulls itself. A page like this is doing all the database accessing! Your computer in game will simply be running a couple of HTTP functions calling the site. Generally they are GET variables.
Here is an example!
(not protected against SQL injection)
<?php $query = $_GET['sql_query']; mysql_query($query);
MySQLi would be more efficient.
Sorry, the 2nd way actually doesn't exists anymore (from what I am aware)
Maybe another user could clean this up for me. There was a mod that could be added to the game and would allow connect to MySQL databases. I am not sure sorry
#3
Posted 22 December 2013 - 09:04 AM
I hosted the code you put on the post above on my xampp server (by the way you forgot the end php tag)
I tried calling the website with the code below
this is the error i got
Bios:451: Invalid URL
Do i need a website that isn't hosted on my pc?
I tried calling the website with the code below
term.clear()
term.setCursorPos(1,1)
http.get("localhost/index.php")
this is the error i got
Bios:451: Invalid URL
Do i need a website that isn't hosted on my pc?
#4
Posted 22 December 2013 - 03:35 PM
Goobster22, on 22 December 2013 - 09:04 AM, said:
I hosted the code you put on the post above on my xampp server (by the way you forgot the end php tag)
I tried calling the website with the code below
this is the error i got
Bios:451: Invalid URL
Do i need a website that isn't hosted on my pc?
I tried calling the website with the code below
term.clear()
term.setCursorPos(1,1)
http.get("localhost/index.php")
this is the error i got
Bios:451: Invalid URL
Do i need a website that isn't hosted on my pc?
term.clear()
term.setCursorPos(1,1)
http.get("http://localhost/index.php")
You forgot the http part.
#5
Posted 22 December 2013 - 11:39 PM
Ok, with PHP, you don't require the end tag..
** FUTURE USERS :: HAVE A GOOD UNDERSTANDING IN BOTH PHP AND LUA BEFORE ATTEMPTING **
You will need to use:
** FUTURE USERS :: HAVE A GOOD UNDERSTANDING IN BOTH PHP AND LUA BEFORE ATTEMPTING **
You will need to use:
data = http.get("127.0.0.1/index.php?value=whatever")
data = data.readAll()
print(data) -- prints computercraft
<?php
if ($_REQUEST['value'] == 'whatever') {
echo 'computercraft';
}
Edited by Imque, 22 December 2013 - 11:39 PM.
#6
Posted 23 December 2013 - 10:22 AM
Thank you guys sooooooo much. I'm so happy it worked. 
thanks for the amazing advice.
thanks for the amazing advice.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











