Sign in to follow this  

[web] Simple PHP and MySQL Example

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
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.


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

<?php
include '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 this post


Link to post
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]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this