# [web] Simple PHP and MySQL Example

This topic is 4027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Thats basically it. I need a simple PHP and MySQL example that accesses a database called TestDatabase and returns the value from TestTable or if someone knows were I may find a simple example like that.

##### Share on other sites
You can start here, here, here, here, here or here.

[google] is my friend, make it yours today for no extra cost.

##### Share on other sites

rly

just type in "php with mysql" and there you go

##### Share on other sites
WOW... Never would think I would get such useless answers. already looked at all of them not really what I was looking for but... THANKS ANYWAY!!....not.

##### Share on other sites
Useless, eh?

How could it be made simpler than the examples posted on the many pages linked above? Create a connection, execute a query, fetch the result(s), print the data, close the connection, end of story. It's really that simple. No really, it is.

If you won't take the time to learn and understand from the links above, then you're never going to learn it. That's basically it.

##### Share on other sites
Already did lean it. By the time I posted that but all of the likes you gave didn't have any Simple PHP and MySQL examples they were tutorials. I hate tutorials it takes longer to do them then it does just to figure it out by your self.

##### Share on other sites
Quote:
 Original post by EmptyVoidAlready did lean it. By the time I posted that but all of the likes you gave didn't have any Simple PHP and MySQL examples they were tutorials. I hate tutorials it takes longer to do them then it does just to figure it out by your self.

Connecting to a database

<?php$dbhost = 'localhost';$dbuser = 'root';$dbpass = 'password';$conn = mysql_connect($dbhost,$dbuser, $dbpass) or die ('Error connecting to mysql');$dbname = 'petstore';mysql_select_db($dbname);?> So hard. Returns a value from a specific table <?phpinclude 'config.php';include 'opendb.php';$query  = "SELECT name, subject, message FROM contact";$result = mysql_query($query);while($row = mysql_fetch_array($result, MYSQL_ASSOC)){    echo "Name :{$row['name']} <br>" . "Subject : {$row['subject']} <br>" .         "Message : {\$row['message']} <br><br>";}include 'closedb.php';?>

Even harder.

By saying you learned it means you know what the above two pieces of script do. If you know what those do, then selecting a row (value) in TestTable by connecting (accessing) a database called TestDatabase should be a piece of cake. If you want a full understanding, read those pages word for word. If you want to see the code to do it, then look at the code. Griping about it does not help you one bit. I really can't see how it would be made easier. Maybe if it specifically said "a simple PHP and MySQL example"?

I'm trying not to be rude, but you've got the information you need; if you don't understand what "this" or "that" is telling you, then you should say so and then we can help you get a better understanding. Here, I'll make it "simple" for you by giving you the steps:

1. Connect to a database (see example above)
2. Select a database (see example above)
3. Execute a query (this is the proper terminology for sending a query to the selected database) (see example above)
4. Fetch the results (this is the proper terminology for pulling data from the specified table in your query) (see example above)
5. Output your results as you iterate through them; you can also collect the results in an array to be used later (see example above)

Any questions?

##### Share on other sites
OK fine to avoid having my rating drop... Your right I'm wrong sorry for being stupid and lazy. Forgive me for being to lazy to read a 10 page tutorial and sorry for figuring it out within 10 seconds after I posted this thread. Sorry for posting this thread because we all know it was a nob question and sorry for being an !@#... I just hope us game developers can one day learn to work together as one. [sad]

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631719
• Total Posts
3001883
×