Home > php教程 > php手册 > 测试php连接mysql是否成功的代码分享

测试php连接mysql是否成功的代码分享

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:25:20
Original
1034 people have browsed it

很多情况下我们不知道是php错误,还是mysql用户名密码不对导致cms运行错误,可以先用下面的代码测试一下就可以了

方法很简单:

将下面的代码保存为test.php,放到web目录里面执行即可。

复制代码 代码如下:


/**
* 测试php与mysql连接
* 编辑:
*/
$link=mysql_connect("localhost","root","123");
if(!$link) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";
?>

其中mysql_connect( )函数的参数依次为:mysql服务器名或IP、mysql用户名,,mysql用户密码。

Related labels:
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
Latest Issues
php - mysql monitoring problem
From 1970-01-01 08:00:00
0
0
0
PHP toolbox mysql cannot start
From 1970-01-01 08:00:00
0
0
0
How to upgrade mysql in php toolbox
From 1970-01-01 08:00:00
0
0
0
Can the php toolbox change the mysql version?
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template