Pages

Tuesday, July 10, 2012

Connecting to the server and selecting a database

The addition to the new function mysql_select_db('address_db') facilitates connection to a database. In this case the database I created bears the name address_db.Though you are free to use any of your choice.

<?php

$server_connect = @mysql_connect('localhost', 'root', '');
$database_select = @mysql_select_db('address_db');

//If server connection fails
if(!$server_connect){
    echo 'Server connection Error!<br />';
}

//If database connection fails
if(!$database_select){
    echo 'Database connection Error!';
}
?>

Save it as connection.php. And run it through your localhost

No comments:

Post a Comment