php - MAMP on Yosemite - connection error : SQLSTATE[HY000] [2002] No such file or directory -


i know have seen question before have not seen answer has been able fix issue on machine.

i'm relatively new php , have no experience apache settings.

i using latest version of mamp (not pro) default settings on latest version of os x (10.3.3).

when try connect via pdo receive following error:

unable connect database server.exception 'pdoexception' message 'sqlstate[hy000] [2002] no such file or directory' in /applications/mamp/htdocs/resources/config.php:7 stack trace: #0 /applications/mamp/htdocs/resources/config.php(7): pdo->__construct('mysql:host=loca...', 'username', 'password') #1 /applications/mamp/htdocs/website/index.php(2): include_once('/applications/m...') #2 {main}

the connection code kevin yank's novice ninja book, modified apply database, username, etc.

try {   $pdo = new pdo('mysql:host=localhost;dbname=db', $dbuser,$dbpass); } catch (pdoexception $e) {    $error = 'unable connect database server.' . $e;   include 'error.html.php';   exit(); } 

i have tried localhost , 127.0.0.1 , same error regardless.

i don't see in console may not looking right thing.

any appreciated.

this happen if mysqld not running (stuff happens). happen if have configuration error.

for example, on installation, reproduce error dsn :

mysql:unix_socket=/tmp/mysqle.sock;dbname=notifications;charset=utf8  

the config calls /tmp/mysql.sock

check config see method configured (port or socket) , (port or socket). if have wrong port or socket in dsn, produce same error report in question.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -