Re: [PHP] php cli and mysql
# [EMAIL PROTECTED] / 2006-11-14 18:56:01 -0500: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. He didn't have trouble running the mysql server (in fact the original message said the same script worked when run from apache). So even if the file was there mysql wouldn't listen on it. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
FYI - the problem with mysql.sock has been an support issue at apple.com before. http://docs.info.apple.com/article.html?artnum=301457 /frank 15 nov 2006 kl. 11.03 skrev Roman Neuhauser: # [EMAIL PROTECTED] / 2006-11-14 18:56:01 -0500: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. He didn't have trouble running the mysql server (in fact the original message said the same script worked when run from apache). So even if the file was there mysql wouldn't listen on it. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- 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] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock On 11/14/06, James Tu [EMAIL PROTECTED] 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
Re: [PHP] php cli and mysql
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 [EMAIL PROTECTED] 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
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 [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Please see below On Nov 14, 2006, at 2:24 PM, [EMAIL PROTECTED] wrote: Run this command: /path/to/cli/php -i|grep MYSQL_SOCKET MYSQL_SOCKET = /var/mysql/mysql.sock What does that show? It sounds like the PHP module for Apache is using a different php.ini file then the CLI version. I know for a fact that Apache is using: /usr/local/php5/lib/php.ini 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 Configuration File (php.ini) Path = /etc but when I looked inside /etc there was no php.ini, but there is a php.ini.default... I could create another here... or should I create a symbolic link to the php.ini that Apache is using? 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 [EMAIL PROTECTED] 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 -- 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
Re: [PHP] php cli and mysql
James Tu wrote: Please see below .. you fell foul of the 'there is no php.ini' trap :-) (please repeat in a homer simpson voice) or should I create a symbolic link to the php.ini that Apache is using? use a seperate php.ini - more flexibility 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? pointing the CLI at the actual .sock seems least invasive, no? rgds, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
You could make a new php.ini for flexibility like Jochem stated. To make things easy, just copy the file over: cp /usr/local/php5/lib/php.ini /etc/php.ini And that should do it. James Tu wrote: Please see below On Nov 14, 2006, at 2:24 PM, [EMAIL PROTECTED] wrote: Run this command: /path/to/cli/php -i|grep MYSQL_SOCKET MYSQL_SOCKET = /var/mysql/mysql.sock What does that show? It sounds like the PHP module for Apache is using a different php.ini file then the CLI version. I know for a fact that Apache is using: /usr/local/php5/lib/php.ini 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 Configuration File (php.ini) Path = /etc but when I looked inside /etc there was no php.ini, but there is a php.ini.default... I could create another here... or should I create a symbolic link to the php.ini that Apache is using? 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 [EMAIL PROTECTED] 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 --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
Re: [PHP] php cli and mysql
Thanks everyone! On Nov 14, 2006, at 3:20 PM, [EMAIL PROTECTED] wrote: You could make a new php.ini for flexibility like Jochem stated. To make things easy, just copy the file over: cp /usr/local/php5/lib/php.ini /etc/php.ini And that should do it. James Tu wrote: Please see below On Nov 14, 2006, at 2:24 PM, [EMAIL PROTECTED] wrote: Run this command: /path/to/cli/php -i|grep MYSQL_SOCKET MYSQL_SOCKET = /var/mysql/mysql.sock What does that show? It sounds like the PHP module for Apache is using a different php.ini file then the CLI version. I know for a fact that Apache is using: /usr/local/php5/lib/php.ini 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 Configuration File (php.ini) Path = /etc but when I looked inside /etc there was no php.ini, but there is a php.ini.default... I could create another here... or should I create a symbolic link to the php.ini that Apache is using? 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 [EMAIL PROTECTED] 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 --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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
# [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Tom Ray [Lists] wrote: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. Actually the opposite - it becomes a lot harder to debug/diagnose. PHP uses the socket file to talk to mysql if you connect to 'localhost' rather than using a tcp/ip connection. If the socket file is invalid (as this would be), then mysql_connect fails, mysql_query fails and so on. The problem as it turns out was that php was looking in the wrong place, if this file was there and empty, then you'd get completely different errors which would make it harder to find the original problem. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Chris wrote: Tom Ray [Lists] wrote: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. Actually the opposite - it becomes a lot harder to debug/diagnose. PHP uses the socket file to talk to mysql if you connect to 'localhost' rather than using a tcp/ip connection. If the socket file is invalid (as this would be), then mysql_connect fails, mysql_query fails and so on. The problem as it turns out was that php was looking in the wrong place, if this file was there and empty, then you'd get completely different errors which would make it harder to find the original problem. Well that's odd because on all my servers the mysql.sock is empty and if it's missing mysql tells me it can't find the sock file when it starts up. This wasn't an actual PHP problem, even trying to connect to the mysql server via /usr/local/mysql/bin/mysql -u user -p database would have produced that error. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php cli and mysql
Tom Ray [Lists] wrote: Chris wrote: Tom Ray [Lists] wrote: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2006-11-14 20:17:16 +0200: On 11/14/06, James Tu [EMAIL PROTECTED] 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) touch /var/mysql/mysql.sock chmod 777 /var/mysql/mysql.sock How could that possibly help? Because if the mysql.sock file is missing the mysql server won't start. If the mysql server isn't running the PHP script won't work. So I think it helps a lot. Actually the opposite - it becomes a lot harder to debug/diagnose. PHP uses the socket file to talk to mysql if you connect to 'localhost' rather than using a tcp/ip connection. If the socket file is invalid (as this would be), then mysql_connect fails, mysql_query fails and so on. The problem as it turns out was that php was looking in the wrong place, if this file was there and empty, then you'd get completely different errors which would make it harder to find the original problem. Well that's odd because on all my servers the mysql.sock is empty and if it's missing mysql tells me it can't find the sock file when it starts up. This wasn't an actual PHP problem, even trying to connect to the mysql server via /usr/local/mysql/bin/mysql -u user -p database would have produced that error. It was a php problem. PHP was looking for the socket file in the wrong location. To quote: I found it at /tmp/mysql.sock Why is the CLI looking for it at /var/myslq/mysql.sock? Randomly creating socket files in the location php is looking for doesn't solve this. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php