The mysql_select_db() function is used to select current running database for the application. This function return True for success or false for failure.
PHP mysql_select_db() Function Example:
The mysql_select_db() function is used to select current running database for the application. This function return True for success or false for failure.
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ $db_name = "php_mysql"; mysql_select_db($db_name, $connection); $sql = "select * from user;"; $records = mysql_query($sql, $connection); while($rows = mysql_fetch_array($records)){ echo "User Id : " . $rows['user_id'] . "<br />"; echo "User Name : " . $rows['user_name'] . "<br />"; echo "User Email : " . $rows['user_email'] . "<br />"; echo "User Address : " . $rows['user_address'] . "<br /><br /><br />"; } } mysql_close($connection); ?>
In this example we have used mysql_select_db() function and select "php_mysql" database for perform mysql operation on it.
The "php_mysql" database on the mysql server have 'user' table and the records in the 'user' table is:
After running example the browser output is:
Output:
User Id : 3 User Name : Deepak User Email : deepak@rediffmail.com User Address : Noida User Id : 4 User Name : Dipali User Email : dipali@hotmail.com User Address : Guraun
[ 0 ] Comments