How do I connect to mySQL from PHP?
Luckily there are a couple of functions in PHP that make it easy. Once you get it working you can just copy and paste at the top of each script that requires the database or use a template or include file of some sort to include the details.
<?php
$db = mysql_connect("HOST", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE_NAME",$db);
?>
And that's all there is to it - use your username, host, password and database name and this will establish the connection.
The most common problem is that you get the password wrong so double check it's right if you get errors.
Comment on this Question and Answer >>>
ASK A QUESTION
More mysql PHP Questions
How do I group the results of a mysql query?My website www.quicheandpie.com has navigation buttons which were added by going to admin/categorylist and adding a category. I can add category = navigation buttons and update them, but I can not delete them. Any ideas how I can find where the info
What is difference between mysql_fetch_array and mysql_fetch_object?
How do I find the number of rows in a result set?
how to write sessions in php code?
