问题
The code below worked on my old iMac with MAMP. However, it does not work on my new iMac. How do I fix this? Do I need to do something to the php.ini
file?
<?php
$dbConnection = mysqli_connect("localhost", "xxxx", "xxxx", "gallery");
$query = "SELECT * FROM images";
$stmt = mysqli_prepare($dbConnection,$query);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $id, $categories,$img_name);
while (mysqli_stmt_fetch($stmt)) {
echo $id."<br />";
}
?>
回答1:
You should enable php_mysqli extension in PHP.ini. It's disabled by default.
look for the following line: extension=php_mysqli
回答2:
I grappled with this one for most of a day before the following on the (localhost) MAMP home page caught my eye: if you're running a PHP version 5.5.x or earlier, mysqli_connect() should work fine, but if you're using PHP version 5.6.x or later, try mysqli_init() and see if that works for you. It worked for me! It displays under the heading "Examples". Good luck!
回答3:
The problem: a column name was missing from the bind statement.
来源:https://stackoverflow.com/questions/9420701/mysqli-connect-not-working-on-mamp