Home >Database >Mysql Tutorial >How to test whether the database connection is successful in mysql
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');].
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('localhost', 'root', '123456');//创建连接 if ($link) //如果连接失败 { echo '服务器的基本信息是:' .mysql_get_host_info($link); } else//数据库连接成功 { echo '连接失败:' . 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!