安装好php apatche mysql 以后 做链接测试:
写了一个链接数据库的文件:
<?php
echo "<h1>This test for mysql.</h1>";
/* 连接选择数据库 */
$link = mysql_connect("localhost", "root", "admin")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("test
") or die("Could not select database"); /* test
是我自己新建的数据库*/
/* 执行 SQL 查询 */
$query = "SELECT * FROM friends
"; /*friends
也是我自己新建的表*/
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* 在 HTML 中打印结果 */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
?>
结果报错说Call to undefined function mysql_connect
我又写了个页查看php状态 用phpinfo();
发现里面没有mysql 这项,可是我在php.ini 里extension = php_mysql.dll 前的分号已经去掉了
而且 php\ext\php_mysql.dll也是存在的!
搜索了一下相关问题,找到答案了,原来是需要copy2个文件到c:\windows里的
1、D:\php\ext\php_mysql.dll 2、D:\php\libmysql.dll
重新启动Apache 刷新页面 正常显示啦!哈哈~
本文介绍了如何解决PHP连接MySQL数据库失败的问题,通过调整php.ini配置并确保相关dll文件正确放置,最终实现成功连接。
1万+

被折叠的 条评论
为什么被折叠?



