通过php连接mysql出现问题

zwb0619 2006-08-19 09:49:31

执行如下代码:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", $mysqli->host_info);

/* close connection */
$mysqli->close();
?>

但是出现以下错误:
Fatal error: Class 'mysqli' not found in E:\web\PHPDocument1.php on line 2


执行以下代码:
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));

/* close connection */
mysqli_close($link);
?>

出现如下错误:
Fatal error: Call to undefined function mysqli_connect() in E:\web\PHPDocument1.php on line 2


我的mysql版本是5.0.20,我的php版本是5.1.1

...全文
468 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
benzenez 2006-08-19
  • 打赏
  • 举报
回复
转载
Try these:

- edit the "php.ini" file and check that "extension_dir" entry is set

- in "php.ini", go to Windows Extensions area and check that extension=php_mysql.dll line exists

- on hard disk, go to the folder set by "extension_dir" at first step and check that "php_mysql.dll" file is copied there.

Because the MySQL changed the licensing type some time ago the PHP guys were forced by this new license to not distribute the php_mysql module as an active module default into their configuration. This problem created a lots of confusion because like into your case you have to enable the extension as my colleague has already described you but you also have to copy the mysql client library against which this module was compiled from the PHP5 distro folder into the C:/Windows/system32 or to any other path that is it present on your server PATH configuration otherwise the module won't function.



wen8u8 2006-08-19
  • 打赏
  • 举报
回复
查看一下.ini中mysqli扩展有没有加载
zwb0619 2006-08-19
  • 打赏
  • 举报
回复
唉,不知道怎么回事,刚才用mysql_connect()函数可以连接到数据库,但是用mysqli方式却不行
zwb0619 2006-08-19
  • 打赏
  • 举报
回复
我已经检查过了,php.ini没问题,相关文件也复制到了C:/Windows/system32

就是会有这样的问题

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧