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?

王林
Release: 2023-08-27 22:46:01
forward
1066 people have browsed it

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>
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template