php 在 MAMP 中连接到 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16550942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:20:38  来源:igfitidea点击:

Connect to MySQL in MAMP

phpmysqlmamp

提问by Ashish Agarwal

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

我正在尝试将 HTML 表单连接到 MAMP 上的 MySQL 数据库。

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

但是我无法打开 MySQL 连接。我不断收到消息“无法连接”

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 ..
  1. 主机不正确
  2. 用户名和/或密码不正确。我在 config.inc.php 中找到了这个信息,所以我相信它是正确的,但有一种可能性..

Here's the PHP script

这是 PHP 脚本

<?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";
        }
    }   
}

?>

?>

回答by Daniel Kmak

Possible solutions from this thread:

此线程的可能解决方案:

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

a) 启动 MAMP,转到 Preferences 并将SQL Port设置为3306

b) Use this set of commands:

b) 使用这组命令:

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

in the Terminal and restart MAMP.

在终端中并重新启动 MAMP。

Have a nice day.

祝你今天过得愉快。