Home >Database >Mysql Tutorial >How to test whether the database connection is successful in mysql

How to test whether the database connection is successful in mysql

coldplay.xixi
coldplay.xixiOriginal
2021-01-06 10:29:267611browse

Mysql method to test whether the database connection is successful: first open all relevant ports; then restart iis, the code is [$link = mysql_connect('localhost', 'root', '123456');].

How to test whether the database connection is successful in mysql

The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22, DELL G3 computer. This method is suitable for all brands of computers.

Related free learning recommendations: mysql video tutorial

Mysql method to test whether the database connection is successful:

Test whether the database is connected successfully The connection is successful

<?php
$link=mysql_connect(localhost,root,land);
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>

If

Fatal error: Calltoundefinedfunctionmysql_connect() in ......”

appears, don’t panic

We will

     ;extension=php_dba.dll
      ;extension=php_gd2.dll
      ;extension=php_mbstring.dll
      ;extension=php_mcrypt.dll
      ;extension=php_mysql.dll
      ;extension=php_mysqli.dll
      ;extension=php_pdo.dll
      ;extension=php_pdo_mysql.dll
;extension=php_mbstring.dll
       ;extension=php_gd2.dll
       ;extension=php_mysql.dll
       ;extension=php_mcrypt.dll

enable all

and then restart iis. It will be successful

   <html>
        <head>
         <title>连接数据库</title>
        </head>
        <body>
         <?php
            $link = mysql_connect(&#39;localhost&#39;, &#39;root&#39;, &#39;123456&#39;);//创建连接
            if ($link) //如果连接失败
               {
                 echo &#39;服务器的基本信息是:&#39; .mysql_get_host_info($link);
               }
            else//数据库连接成功
               {
                 echo &#39;连接失败:&#39; . mysql_error();
               }
            mysql_close($link);  //关闭连接
         ?>
        </body>
       </html>

The above is the detailed content of How to test whether the database connection is successful in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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