编写示例,使用 PHP 脚本建立 MySQL 数据库连接?


我们可以使用以下的 PHP 脚本建立一个 MySQL 数据库连接,其用户名为“guest”,密码为“guest123”。

<html>
   <head>
      <title>Connecting MySQL Server</title>
   </head>
   <body>
      <?php
         $dbhost = 'localhost:3306';
         $dbuser = 'guest';
         $dbpass = 'guest123';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_close($conn);
      ?>
   </body>
</html>

更新于:2020 年 6 月 22 日

137 次浏览

开启你的 职业生涯

通过完成课程获取认证

开始学习
广告
© . All rights reserved.