数据库
首页 > 数据库> > php-如何在Mac OS X Snow Leopard上启用mysqli?

php-如何在Mac OS X Snow Leopard上启用mysqli?

作者:互联网

我正在尝试在Mac OS X上启用mysqli.我正在使用MAMP,并且已经尝试过XAMPP(我对其中任何一个都开放),但是当我打开php.ini文件并搜索任何包含单词“ mysqli”的内容时,找不到任何内容. ,当我尝试运行包含任何mysqli代码的PHP脚本时,什么也没发生:没有错误输出,该脚本执行失败.

当我尝试通过

$dbh = new mysqli("localhost","root","root");

我转储输出的变量$dbh:

object(mysqli)#1 (17) { ["affected_rows"]=> int(0) ["client_info"]=> string(5) "5.5.9" ["client_version"]=> int(50509) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(5) "5.5.9" ["server_version"]=> int(50509) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(12) ["warning_count"]=> int(0) }

这是我尝试的代码:

$dbh = new mysqli("localhost","root","root");
$dbh->select_db("php");
$dbh->query("SELECT * FROM test");
$count = $dbh->num_rows;
var_dump($count);

输出是

NULL

解决方法:

确保启用了mysqli:

将以下内容写入您的Web目录中的php文件(我使用的是本机php,因此将其放在/ Library / WebServer / Documents /中):

<?php phpinfo(); ?>

然后在输出中检查单词“ mysqli”

标签:mysqli,xampp,mamp,mysql,php
来源: https://codeday.me/bug/20191208/2088578.html