I prefer running php scripts in the shell as the output comes directly and not in tranches like in a browser. This can be very helpful to see the script is actually still working and also to see which part of a long script takes the longest.
When I call php scripts from the shell like this
php filename.php
it works fine, but only so long as no db connection is established in the script.
Apparently, the mysql_connect() seems to fail:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
How can I fix this?
Thanks!
Charles
EDIT 1
I connect to the db as follows:
//Connect to db
$user="root";
$databasePassword="";
$host="localhost";
$database="database1";
$identifier=mysql_connect($host,$user,$databasePassword,true);
$db1=mysql_select_db($database);
SOLUTION FOUND
This showed me the right way to do it - it's as simple as replacing "localhost" with "127.0.0.1", because: "The reason is that "localhost" is a special name for the mysql driver making it use the unix socket to connect to mysql instead of the a tcp socket."