PHP MySQL Connect to Database
From w3cyberlearnings
Contents |
PHP MySQL Select Database
Use or select database to use.
Syntax
mysql_select_db(database_name);
Example 1
<?php define('HOST', 'localhost'); define('USER', 'root'); define('PASS', 'yeething'); define('DBNAME', 'woowood'); $connection = mysql_connect(HOST, USER, PASS); if (!$connection) { die("can not connect to the server!<br/>"); } else { $rdb = mysql_select_db(DBNAME); if (!$rdb) { die("The " . DBNAME . "database could not be selected"); } else { echo "Database " . DBNAME . " is ready for use."; } } mysql_close($connection); ?>
Output
Database woowood is ready for use.