php cli and mysql



I'm running a php script from the command line (I'm on OS X) and I'm getting ...

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

Here's the script (this just tests a connection and a query...the actual script imports data from text files):


#!/usr/bin/php
<?php

echo "HELLO WORLD\n";
$connection = mysql_connect(HOST, ID, PW);
mysql_select_db(DB, $connection);
$result = mysql_query("SELECT COUNT(*) as num_of_countries from geo_entities");
$row = mysql_fetch_array($result);
print_r($row);

?>


I tested the script from a browser and the connection and query worked.
Do I have to do something special in order for PHP CLI to connect to MySQL?

-James
.



Relevant Pages

  • RE: [PHP] Closing a connection to browser without exiting the script
    ... Closing a connection to browser without exiting the ... I have a PHP page that displays a message, and then, performs a very ... what I would like is to be able to close the connection from ... the server-side, but without using the exitfunction, so my script ...
    (php.general)
  • Re: [PHP] php cli and mysql
    ... Warning: mysql_connect: Can't connect to local MySQL server through ... Here's the script (this just tests a connection and a query...the ... Do I have to do something special in order for PHP CLI to connect to ...
    (php.general)
  • Re: mysqli connections and oop
    ... And here is the script that execute this ... lose a mysqli connection upon the reload of the page? ...
    (comp.lang.php)
  • Re: [PHP] Closing a connection to browser without exiting the script
    ... A fresh Ajax call to the script starts a new ... The only way to have a "stay-resident" PHP daemon for Ajax callbacks would be ... find a way to close my connection to the browser (using ...
    (php.general)
  • PHP 5.0.0 and the OCI8 module
    ... I am relatively new to PHP, but with over a decade of experience in C ... and other programming languages I can usually pick up a new ... The script is run on the command line as: ... connection methods is utilized, the script also runs to completion. ...
    (comp.lang.php)