Transmitting a MySQL SELECT query
bool/string mysql_select_db(string $db_name)
true on success, otherwise false or response data
<?php
include_once "/lib/sn_dns.php"; // include DNS library
include_once "/lib/sn_mysql.php";
$db_name = "testdb"; // database's name to select
$query_create_db = "CREATE DATABASE $db_name;"; // SQL sentance to make a database
$query_drop_db = "DROP DATABASE $db_name;"; // SQL sentance to delete a database
$server_addr = "192.168.0.100"; // IP address of MySQL server
$user_name = "user_id"; // MySQL ID
$password = "password"; // MySQL password
// connect to a MySQL server
if(mysql_connect($server_addr, $user_name, $password) === false)
exit(mysql_error()); // print the error message and quit
if(mysql_query($query_create_db) === false) // send a query to make a database
exit(mysql_error()); // print the error message and quit
if(mysql_select_db($db_name) === true) // select the database
echo "Database $db_name is selected!\r\n";
else
exit(mysql_error()); // print the error message and quit
if(mysql_query($query_drop_db) === false) // send a query to delete the database
exit(mysql_error()); // print the error message and quit
mysql_close(); // disconnecting from the MySQL server
?>