Connecting to MySQL with PHP

An example of connecting to MySQL with PHP.

You can connect to MySQL with hostname “localhost”.

The following example connects to database “cpname_database” with username “cpname_user” and password “your_password”. You will need to substitute these values for your actual database, username, and password you setup in the hosting control panel (instructions)

////// establish connection to MySQL as the "cpname_user" user and make "cpname_database" the current database //////
$link = mysqli_connect('localhost', 'cpname_user', 'your_password', 'cpname_database');

if (!$link) {
   die('Not connected : ' . mysqli_connect_error());

Please consult the PHP documentation for more details.

Posted 2008-03-10 in Databases,Web Development