Wednesday, 15 January 2014

php - How to track SQL errors in CakePHP on production site -



php - How to track SQL errors in CakePHP on production site -

i want track errors on production site if insert or update function didnot work .

to test fucntionality have cretaed function in controller :-

function testsqlstatement(){ $this->autorender = false; $save=array('userid'=>'48','active'=>'qw'); $this->user->saveall($save); $log = $this->getdatasource()->error; $this->log('sql error' . print_r($log, true), 'sql'); }

the error :- phone call undefined method adminscontroller::getdatasource() have define getdatasource? there other method know error without chaning debug 2

you utilize next way :

the onerror callback gets called dbosource class in create(), read(), update() , delete() methods. so, if writing custom query , calling through model’s query() method onerror() won’t called automatically, don’t worry, can still track sql error(s). these crud methods, alongwith query(), in turn utilize execute() method sets sql error class variable, named ‘error’

the lasterror() methods have been implemented in each dbo source (mysql, mssql etc.).

lets move forwards write our model callback. illustration code log error in text file would like:

<?php function onerror() { // sql error $error = $this->getdatasource()->error; // log file $logfile = logs . 'sql_errors.txt'; // log error file_put_contents($logfile, file_get_contents($logfile) . $error . "\n\n"); }

this code can go in app_model.

another illustration code mail service error function onerror() { // sql error $error = $this->getdatasource()->error; // send error mail('webmaster@example.com', 'sql errors', $error); }

php debugging cakephp

No comments:

Post a Comment