&nb"/> SelectingMySQLDatabase &nb">

Home >Backend Development >PHP Tutorial >How can we select a MySQL database using PHP script?

How can we select a MySQL database using PHP script?

王林
王林forward
2023-08-27 22:45:041080browse

How can we select a MySQL database using PHP script?

We know that PHP provides a function called mysql_select_db to select a mysql database.

Example

To illustrate this, we will use a PHP script in the following example to select a database called "Tutorial".

<html>
   <head>
      <title>Selecting MySQL Database</title>
   </head>
   <body>
      <?php
         $dbhost = &#39;localhost:3036&#39;;
         $dbuser = &#39;guest&#39;;
         $dbpass = &#39;guest123&#39;;
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die(&#39;Could not connect: &#39; . mysql_error());
         }
         echo &#39;Connected successfully&#39;;
         mysql_select_db( &#39;TUTORIALS&#39; );
         mysql_close($conn);
      ?>
   </body>
</html>

The above is the detailed content of How can we select a MySQL database using PHP script?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete