开发者

How do I enable mysqli on Mac OS X Snow Leopard?

I am trying to enable mysqli on Mac OS X. I am using MAMP and I have tried XAMPP (I am open to either), but when I open the php.ini file and search for anything containing the word "mysqli" nothing is found, and when I try to run a PHP script containing any mysqli code, nothing happens: no errors are output, the script just fails to execute.

When I try to connect by

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

and I dump the variable $dbh it outputs:

object(mysqli)#1 (17) { ["affected_rows"]=> int(0) ["client_info"]=> string(5) "5.5.9" ["client_version"]=> int(50509) ["conn开发者_如何学Cect_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) }

This is the code I tried:

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

and the output is

NULL


If you still cannot connect:

Try using hostname 127.0.0.1 instead of localhost.

Mysql won't let me connect with localhost unless host is % (I know this is a hack)

I don't know the reason yet, but I will update my answer as soon as I find it.


Make sure that mysqli is enabled:

Write the following to a php file in your web directory (I'm using native php, so I put it in /Library/WebServer/Documents/):

<?php phpinfo(); ?>

Then check the output for the word "mysqli"


You have to stored the result in to MySQLi_Result class. Otherwise, you can use affected_rows variable to show the similar effect.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜