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

问题描述 投票:3回答:3

我正在尝试在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
php mysql mysqli xampp mamp
3个回答
2
投票

确保启用了mysqli:

将以下内容写入您的web目录中的php文件(我使用的是本机php,所以我把它放在/ Library / WebServer / Documents /中):

<?php phpinfo(); ?>

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


1
投票

您必须将结果存储到MySQLi_Result类中。否则,您可以使用affected_rows变量来显示类似的效果。

$result = $dbh->query("SELECT * FROM test");
$count = $result->num_rows;
$count = $dbh->affected_rows;

0
投票

如果仍然无法连接:

尝试使用主机名127.0.0.1而不是localhost

Mysql不会让我连接localhost,除非主机是%(我知道这是一个hack)

我还不知道原因,但是一旦找到它我就会更新我的答案。

© www.soinside.com 2019 - 2024. All rights reserved.