Jump to content




Data Base help


  • You cannot reply to this topic
5 replies to this topic

#1 Goobster22

  • Members
  • 7 posts
  • LocationNerd Cave

Posted 21 December 2013 - 07:20 PM

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.

#2 Imque

  • Members
  • 134 posts

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)
<?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 Goobster22

  • Members
  • 7 posts
  • LocationNerd Cave

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

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 rewbycraft

  • Members
  • 5 posts

Posted 22 December 2013 - 03:35 PM

View PostGoobster22, 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

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 Imque

  • Members
  • 134 posts

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:

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 Goobster22

  • Members
  • 7 posts
  • LocationNerd Cave

Posted 23 December 2013 - 10:22 AM

Thank you guys sooooooo much. I'm so happy it worked. :D

thanks for the amazing advice. :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users