Page 1 of 1
Making SQL talk to php?
Posted: Sat Feb 20, 2010 7:28 am
by Age of Fable
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.
Re: Making SQL talk to php?
Posted: Sat Feb 20, 2010 7:59 am
by Jackolantern
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:
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'];
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().
Re: Making SQL talk to php?
Posted: Sat Feb 20, 2010 4:29 pm
by Age of Fable
Thanks!
I just noticed this should probably be in the 'coding' sub-forum

Re: Making SQL talk to php?
Posted: Sat Feb 20, 2010 7:06 pm
by hallsofvallhalla
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
Re: Making SQL talk to php?
Posted: Sun Feb 21, 2010 7:08 pm
by Torniquet
hallsofvallhalla 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
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 lol
Re: Making SQL talk to php?
Posted: Sun Feb 21, 2010 8:01 pm
by Jackolantern
Torniquet wrote:hallsofvallhalla 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
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 lol
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).
Re: Making SQL talk to php?
Posted: Sun Feb 21, 2010 11:35 pm
by Falken
Re: Making SQL talk to php?
Posted: Mon Apr 19, 2010 5:00 pm
by GodSINt
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.