Hi,
Can anyone tell me how to have a php script which can take something out of SQL and use it as a variable?
PS I only have dial-up, so it'd be better not to direct me to a tutorial video.
Making SQL talk to php?
-
- Posts: 54
- Joined: Fri Feb 19, 2010 6:37 am
Making SQL talk to php?
Easy to play - hard to survive. http://www.ageoffable.net
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Making SQL talk to php?
You mean get a PHP variable out of a field in a MySQL database? It's easy! Say you want to get a player's health, which is stored in a field called "health" in the "players" database:
That is assuming you have a connect.php script included at the top of your script that is creating a database resource called $db. If you don't have it, just look at the thread for Halls's video 3, and the script is written out there, ready to copy and paste (you just have to supply your own password and/or user if you are using something besides "root").
EDIT: As a note, I can't remember if you actually have to supply the $db in the mysql_query() function. You have to supply it with mysqli library, which is the one I use, but I wanted to stay compatible with Halls' scripts. If you get a "wrong number/type of parameters" just remove the $db from mysql_query().
Code: Select all
//query db to get data
$storedInfo = mysql_fetch_assoc(mysql_query($db, "SELECT * FROM players WHERE name='$playerName'")) or die("Could not connect to db!");
//make sure something was pulled up
if (!$storedInfo) {
echo "Nothing found for that player!";
exit();
}
//use the storedInfo variable to store the health
$playerHealth = $storedInfo['health'];
EDIT: As a note, I can't remember if you actually have to supply the $db in the mysql_query() function. You have to supply it with mysqli library, which is the one I use, but I wanted to stay compatible with Halls' scripts. If you get a "wrong number/type of parameters" just remove the $db from mysql_query().
The indelible lord of tl;dr
-
- Posts: 54
- Joined: Fri Feb 19, 2010 6:37 am
Re: Making SQL talk to php?
Thanks!
I just noticed this should probably be in the 'coding' sub-forum
I just noticed this should probably be in the 'coding' sub-forum

Easy to play - hard to survive. http://www.ageoffable.net
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Making SQL talk to php?
I know you said do not link to tutorials but just watching my first couple of vid tutorials will only take about 30 minutes and will show you all you need to get mysql and php talking to each other.
moved to coding
moved to coding
Re: Making SQL talk to php?
i dont think its the fact of how long it will take. its more how long it will take to buffer the vid lol. 56k dial up is bloody slow if you may recall from having dial up lolhallsofvallhalla wrote:I know you said do not link to tutorials but just watching my first couple of vid tutorials will only take about 30 minutes and will show you all you need to get mysql and php talking to each other.
moved to coding
New Site Coming Soon! Stay tuned 

- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Making SQL talk to php?
He could use the download links for the video. I agree that it would likely be unviewable watching it stream (unless maybe he pauses it and leaves it to load for a long time).Torniquet wrote:i dont think its the fact of how long it will take. its more how long it will take to buffer the vid lol. 56k dial up is bloody slow if you may recall from having dial up lolhallsofvallhalla wrote:I know you said do not link to tutorials but just watching my first couple of vid tutorials will only take about 30 minutes and will show you all you need to get mysql and php talking to each other.
moved to coding
The indelible lord of tl;dr
Re: Making SQL talk to php?
Or he can read a text tutorial 
Here are a few
http://www.freewebmasterhelp.com/tutorials/phpmysql
http://www.php-mysql-tutorial.com/wikis ... abase.aspx
http://www.w3schools.com/PHP/DEfaULT.asP
Good luck!

Here are a few
http://www.freewebmasterhelp.com/tutorials/phpmysql
http://www.php-mysql-tutorial.com/wikis ... abase.aspx
http://www.w3schools.com/PHP/DEfaULT.asP
Good luck!
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
Re: Making SQL talk to php?
I use my blackberry for my connection via tether, so it's basicly dialup. I just downloaded the vids. didn't take that long because they are zipped allinto 1 file, and it is very much worth the download time to get em. Halls is a BEAST.
