mysqli_connect not working on MAMP

守給你的承諾、 提交于 2019-12-13 08:39:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!