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) ["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) }
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
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"