heapzero
heapzero

Reputation: 1433

Unable to connect to MySQL from PHP : "mysql_connect(): No such file or directory"

I'm not able connect to mysql via php. It produces [error] [client 127.0.0.1] PHP Warning: mysql_connect(): No such file or directory error message in apache error log when executing mysql_connect() function in PHP.

Please find the warning messages when running php -m command:

$ php -m | grep mysql  
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so, 9): image not found in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll, 9): image not found in Unknown on line 0
mysql
mysqli
mysqlnd
pdo_mysql

and

$ mysqladmin -h `hostname` --port=3306 version
/usr/local/mysql/bin/mysqladmin: connect to server at 'heapzero.local' failederror: 'Host '192.168.1.36' is not allowed to connect to this MySQL server'

PHP Version:

$ php --version
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so, 9): image not found in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll, 9): image not found in Unknown on line 0
PHP 5.3.2 (cli) (built: Aug  7 2010 00:04:41) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

MySQL Version:

mysql --version
/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.1.50, for apple-darwin10.3.0 (i386) using readline 5.1

I've spent lot of time in trying to fix this. Please suggest! Thanks!

Upvotes: 4

Views: 5546

Answers (2)

user65535
user65535

Reputation: 247

If you use Mac OS X Lion, try changing the server/host name to IP address instead.
Example: instead of localhost, use 127.0.0.1 in the PHP code.

Upvotes: 8

luther07
luther07

Reputation: 372

Your problem could be related to "remote access". You should try editing the configuration of mysql. The file may be called my.cnf.

Here is a link that may be helpful: http://www.debianhelp.co.uk/remotemysql.htm

Upvotes: 0

Related Questions