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

10,161

Solution 1

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"

Solution 2

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.

Solution 3

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;
Share:
10,161
mcbeav
Author by

mcbeav

Updated on June 04, 2022

Comments

  • mcbeav
    mcbeav about 2 years

    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