log4php Failed connecting to mysql cluster database & could not find driver


My log4php gets this error in a new server environment.
PHP Warning: log4php: [LoggerAppenderPDO:default]: Failed connecting to database. Closing appender. Error: could not find driver in ../log4php/LoggerAppender.php on line 283
I have the same settings for log4php (1. config.xml file 2.same log4php version) as my local development, which works perfectly. I tried simply log to a file in the new server, it works, which means the log4php lib has no problem. And I can even log to the database in the new server from my local script using local log4php lib, which means my server can recognize log4php logging.
Reasons:
After some searches and tests(script using PDO, not mysqli to connect to the database, good reference here and wiki) , I confirm the problem is caused by lacking of pdo_mysql related driver. As log4php uses PDO extensions in PHP to  log to mysql database. Then PDO extension is needed. As PDO is defaultly included from PHP5.1, and our mysql-cluster use mysql 5.5, it should be included. But it is not.  I tried to re-install php5-mysql, but it failed, got server related errors; I tried to modify php.ini and add pdo extensions, got more errors. I guess that is because the mysql-cluster settings are different from normal mysql.  But not sure about this. 

To check whether you have PDO driver, you can use:
$php -i
Then you can see the info in the PDO part:
PDO

PDO support => enabled

PDO drivers =>
Normally, if the PDO has driver, the info should be like this:
PDO

PDO support => enabled
PDO drivers => mysql

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => 5.5.35

Directive => Local Value => Master Value

pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock

Work around:
As the new server is a production server, we decide not to touch it and move the scripts to other server with normal mysql settings, which log4php works perfectly.


Comments

Popular posts from this blog

install postgreSQL in ubuntu 16.04

timestamp with 16, 13 and 10 digits to Qlik date

install ipython in Cloudera VM using pip