Return to "PHP"

Connecting to Databases with PHP


 
The topic of this article is not supported by our customer support department, however for your convenience we are providing this material to assist you in troubleshooting potential issues related to this topic.


PHP and MySQL are extremely easy to use together; most tutorials and books written regarding PHP should have a section explaining the connection between the MySQL database and PHP.


A simple MySQL connection can be opened in PHP using the following code:

$connection = mysql_pconnect(“localhost”,“username“,”password“)
or print “Error connecting to the server.”;
$db = mysql_select_db(“database_name”, $connection)
or print “Error connecting to the database.”;

Be sure to replace username, password, and database_name with the correct MySQL information. The mysql_pconnect() function is the preferred method of connecting to MySQL; using mysql_connect() could unintentionally degrade the performance of your MySQL server by opening too many connections at once.


 

Related Articles: