Home > Database > Mysql Tutorial > body text

How to test whether the database connection is successful in mysql

coldplay.xixi
Release: 2023-01-04 09:38:49
Original
7471 people have browsed it

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();
?>
Copy after login

If

Fatal error: Calltoundefinedfunctionmysql_connect() in ......”
Copy after login

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

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

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!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!