I have a simple php file I want to execute in the terminal:
script.php
echo "script is running";
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "Connection Established\n";
}
mysql_close($con);
I'm running the script in the terminal on MacOs with php script.php
, and I'm getting the following error:
script is running
Warning: mysql_connect(): No such file or directory in
/Applications/MAMP/htdocs/issueManager3/notifications.php on line 5
Could not connect: No such file or directory
However, when I run the script through a web browser, it connects to the database fine.
Am I missing something? Or is there something else I need to set up to achieve database connections through the terminal?
Any help appreciated.