Making SQL talk to php?

C++, C#, Java, PHP, ect...
Post Reply
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Making SQL talk to php?

Post 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.
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Making SQL talk to php?

Post 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().
The indelible lord of tl;dr
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Re: Making SQL talk to php?

Post by Age of Fable »

Thanks!

I just noticed this should probably be in the 'coding' sub-forum :oops:
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Making SQL talk to php?

Post 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
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Making SQL talk to php?

Post 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
New Site Coming Soon! Stay tuned :D
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Making SQL talk to php?

Post 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).
The indelible lord of tl;dr
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Making SQL talk to php?

Post by Falken »

--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
GodSINt
Posts: 8
Joined: Thu Apr 01, 2010 4:41 am

Re: Making SQL talk to php?

Post 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.
Image
Post Reply

Return to “Coding”