4

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

?>

Ashish Agarwal
  • 14,555
  • 31
  • 86
  • 125

2 Answers2

5

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.

Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89
1

I believe the default port for mySQL in MAMP is 8889 web server port is 8888

alQemist
  • 362
  • 4
  • 13