PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Connect to MySQL in MAMP

 February 03, 2022     mamp, mysql, php     No comments   

Issue

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

?>


Solution

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.



Answered By - Daniel Kmak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing