Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 20:25:20
Original
982 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:
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 Recommendations
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!