I’ve read a ton of threads and solutions, I’m not purposely trying to make yet another one of these posts.
Now that thats out of the way
if i run this in my local osx folder (with web sharing on), i get a could not connect error:
<?php
$db = mysql_connect("localhost", "root", "password");
if (!$db) {
die('Could not connect' . mysql_error());
}
echo 'Connected successfully';
yet when i go to terminal and run the following it works fine:
mysql -u root -h 'localhost' -p
password<enter>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1030
Server version: 5.5.25a MySQL Community Server (GPL)
i have updated php.ini to point to /tmp/mysql.sock as well
If you’re just starting out and are using PHP5, you should not use
mysql_connect, but insteadmysqli_connect(use of the mysql extension is discouraged).Check
connect_errorto get more information about why the connection is failing.(Example taken from the above doc)