How can we select a MySQL database by using PHP script?

MySQLMySQLi DatabasePHP

As we know that PHP provides us the function named mysql_select_db to select a mysql database.

Example

To illustrate this we are selecting a database named ‘Tutorials’ with the help of PHP script in the following example −

<html>
   <head>
      <title>Selecting MySQL Database</title>
   </head>
   <body>
      <?php
         $dbhost = 'localhost:3036';
         $dbuser = 'guest';
         $dbpass = 'guest123';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_select_db( 'TUTORIALS' );
         mysql_close($conn);
      ?>
   </body>
</html>
raja
Published on 22-Feb-2018 10:24:40
Advertisements