Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Writing to Databases

Zend_Log_Writer_Db writes log information to a database table using Zend_Db. The constructor of Zend_Log_Writer_Db receives a Zend_Db_Adapter instance, a table name, and a mapping of database columns to event data items:

= array ('host'     => '',
'username' => 'malory',
'password' => '******',
'dbname'   => 'camelot');
$db Zend_Db::factory('PDO_MYSQL'$params);

$columnMapping = array('lvl' => 'priority''msg' => 'message');
$writer = new Zend_Log_Writer_Db($db'log_table_name'$columnMapping);

$logger = new Zend_Log($writer);

$logger->info('Informational message');

The example above writes a single row of log data to the database table named 'log_table_name' table. The database column named 'lvl' receives the priority number and the column named 'msg' receives the log message.

Zend Framework