Re: [PHP] php cli and mysql



Run this command:

/path/to/cli/php -i|grep MYSQL_SOCKET

What does that show? It sounds like the PHP module for Apache is using
a different php.ini file then the CLI version.

It also looks like the CLI versions php.ini is not pointing to the
proper path to the mysql.sock. Look under the mysql section of your
php.ini and fix that up. To see where its pointing, do this:

/path/to/cli/php -i|grep php.ini

That'll tell you where the php.ini file is for the CLI version.

Enjoy.



James Tu wrote:
ok. so the location of mysql.sock is a problem.
I found it at /tmp/mysql.sock

Why is the CLI looking for it at /var/myslq/mysql.sock?

Now the question is...
Do I change the mysql settings so that mysql.sock is at
/tmp/mysql.sock? (If I do, will the PHP module with Apache still be ok?)
or
Do I change where the CLI is looking for mysql.sock?

-James

On Nov 14, 2006, at 1:17 PM, cajbecu wrote:

touch /var/mysql/mysql.sock
chmod 777 /var/mysql/mysql.sock

On 11/14/06, James Tu <jtu@xxxxxxxxxxxxx> wrote:
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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


.



Relevant Pages

  • Re: php_network_getaddresses: getaddrinfo failed
    ... When running the same scipt from the CLI (php ./dns.php), ... This site is available both from apache, and from CLI. ... on a DNS servers change (or new DHCP ...
    (comp.lang.php)
  • Re: php_network_getaddresses: getaddrinfo failed
    ... When running the same scipt from the CLI (php ./dns.php), ... I have another script containing something like this: ... This site is available both from apache, and from CLI. ...
    (comp.lang.php)
  • Re: [PHP] PHP-CLI and the "less" command (kubuntu)
    ... I thought at first it's a problem with Konsole, my terminal program, or with "less" itself. ... But I've now tried in different terminal programs, and reading output other than output from PHP, and the ONLY time it happens is when I pipe output from PHP to "less". ... It may work well the first time, but when repeating the same command a second time, the "weird" behavior starts. ... It could very well be some kind of problem with "less", but since I can only reproduce the problem with output from PHP CLI, I thought it's worth asking here. ...
    (php.general)
  • Re: php_network_getaddresses: getaddrinfo failed
    ... When running the same scipt from the CLI (php ./dns.php), ... I have another script containing something like this: ... This site is available both from apache, and from CLI. ...
    (comp.lang.php)
  • PHP-CLI and the "less" command (kubuntu)
    ... I have a CLI application that produces lots of output to the terminal, so I like to send the output along to the "less" command. ... But I've now tried in different terminal programs, and reading output other than output from PHP, and the ONLY time it happens is when I pipe output from PHP to "less". ... It may work well the first time, but when repeating the same command a second time, the "weird" behavior starts. ... It could very well be some kind of problem with "less", but since I can only reproduce the problem with output from PHP CLI, I thought it's worth asking here. ...
    (php.general)