Connecting to a MySQL Database : mysql_connect « MySQL Database « PHP






Connecting to a MySQL Database

 
resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) 


<?php 
try { 
    $mysqlhost = "localhost"; 
    $mysqluser = "root"; 
    $mysqlpass = ""; 
    if ($db = mysql_connect ($mysqlhost,$mysqluser,$mysqlpass)){ 
        echo "Successfully connected to the database."; 
        mysql_close ($db); 
    
    } else { 
        throw new exception ("Sorry, could not connect to mysql."); 
    } 
} catch (exception $e) { 
echo $e->getmessage (); 
} 
?>
  
  








Related examples in the same category

1.A function to open a connection to mysql
2.Connecting user
3.Creating databases
4.When connecting to multiple MySQL servers, a link ID must be generated.