Connect to MySQL in MAMP

空扰寡人 提交于 2019-12-10 11:33:33

问题


I'm trying to make a HTML form connect to a MySQL database on my MAMP.

However I'm not able to open the MySQL connection. I keep getting the message "Could not connect"

My thoughts for this -

  1. The host is incorrect
  2. The username and/or password is incorrect. I found this information in config.inc.php, so I believe it is correct, but there's a possibility ..

Here's the PHP script

<?php
class Database {
    function insert() {
        $dbhost = 'localhost:8888';
        $conn = mysql_connect($dbhost, 'root', 'root');
        if (! $conn) {
            die('Could not connect: ' . mysql_error());
        }
        else {
            echo "connected";
        }
    }   
}

?>


回答1:


Possible solutions from this thread:

a) Launch MAMP, go to Preferences and set SQL Port to 3306.

b) Use this set of commands:

ps aux | grep mysql 
lsof -i 
killall -9 mysqld 

in the Terminal and restart MAMP.

Have a nice day.



来源:https://stackoverflow.com/questions/16550942/connect-to-mysql-in-mamp

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