Reputation: 35
I'm totally confused here. I have MAMP on an iMac it says MySQL is running. When I try access it via Sequel Pro I can connect using the socket option
However if I try to connect using the Standard method I get a 'connection refused'
When I try connect with PHP I get the connection refused message
$db = new PDO("mysql:host=127.0.0.1:8889;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );
I'm confused because obviously mysql is running (because I can connect one way).
I have the same setup on my MacBook and it all works perfectly
Any suggestions?
Many Thanks!
Upvotes: 0
Views: 991
Reputation: 34416
The standard port for MySQL is 3306 and does not need to be specified in the connection:
$db = new PDO("mysql:host=127.0.0.1;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );
To specify a database connection port use the following DSN string:
$db = new PDO("mysql:host=127.0.0.1;port=3306;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );
You can test 3306 in your Sequel Pro in your standard connection. In addition, you may have to change the host from 127.0.0.1
to localhost
depending on how you're set up.
Upvotes: 1