需要帮助使用PDO在终端中执行php文件

I am trying to execute a php file on the terminal getting an error message(below).

It works find when i open the file on the browser but doesn't work on the terminal.

I also installed PHP using MAMP... could that be the reason why its not working?

Any help would be really appreciated!!

here is the code I am using to connect to the db

$db = new PDO("mysql:host=localhost;dbname=online_ordering","root","root");


'Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' 

FOllowed by this error message

 PDO->__construct('mysql:host=loca...', 'root', 'root')
#1 {main}
  thrown in (path) 

This looks like the same error that's thrown when the mysql server isn't started up.