PHP SQL Select

PHP SQL Select is used to execute mysql select query in the php application. The PHP SQL Select uses mysql_select_db () function that set the active MySQL database.

PHP SQL Select

PHP SQL Select

     

PHP SQL Select is used to execute mysql select query in the php application. The PHP SQL Select uses mysql_select_db () function that set the active MySQL database. The function returns true on successful connection, or False on failure of connection. To perform SQL Select query in PHP, we must create a database connection between the PHP and MySQL.

Understand with Example

This example illustrates how to execute mysql select query in the php application. In the previous example we have already execute many more select query for retrieving data from database but in this example we show the use of  mysql_select_db function in php application. The sql_select.php starts with <? php and end with />. The <?php enclosed the con variable assigned the value of mysql_connect () function that accept the local host, user and pass. The die () script part will be executed in case of connection failure corresponding to specific print message on browser. The mysql_select_db () function accept parameter database and connection.

database : This is used to specifies the name of database to be select.

connection : This specifies the MySQL connection. If it is not specified, the last connection opened by mysql_connect () is used.

Source Code of sql_select.php 

<?php
  $user="root";
  $pass="root";
  $dbname="test";
  $con = mysql_connect("localhost", $user, $passor 

   die("Connection Failure to Database");

  echo "Connected to database server successfully<br>";

  mysql_select_db($dbname, $conor die ($dbname . 

   "Database not found" . $user);

  echo "Database: " " | ". $dbname ." | "" is selected";

  mysql_close($con);
?>

Download Source Code

Output: