There is a functionality called Logging, but I didn't find out yet where the Log class comes from - see unit tests.
Here's an example of logging:
1 require_once 'php-activerecord/ActiveRecord.php';
2
3 ActiveRecord\Config::initialize(function($cfg)
4 {
5 // normal cfg settings above
6 $logger = Log::singleton('file','/path/to/app/logs/phpar.log','ident',array('mode' => 0664, 'timeFormat' => '%Y-%m-%d %H:%M:%S'));
7
8 $cfg->set_logging(true);
9 $cfg->set_logger($logger);
10 });
Oh, I see, it uses the pear package:
http://pear.php.net/package/Log/redirected
or
pear install Log
Awesome sauce, thank you.
For those who need a step-by-step (my local dev is xampp on windows, so YMMV):
1. Make sure you have pear installed and working
2. To install the Log package from pear:
2.1. Open up a command promt
2.2. Navigate to your php directory in xampp (mine is E:\xampp\php)
2.3 Type "pear list" and check if Log is installed.
2.4 If Log is not installed, then type "pear install Log". You should get some messages in the cmd console that "install ok"
3. To use Log, follows Jacques code above, but also make sure that you include the Log.php file from the pear package:
1 require_once 'php-activerecord/ActiveRecord.php';
2 require_once 'E:\xampp\php\PEAR\Log.php';
3
4 ActiveRecordConfig::initialize(function($cfg)
5 {
6 // normal cfg settings above
7 $logger = Log::singleton('file','/path/to/app/logs/phpar.log','ident',array('mode' => 0664, 'timeFormat' => '%Y-%m-%d %H:%M:%S'));
8
9 $cfg->set_logging(true);
10 $cfg->set_logger($logger); });
For more information, also see http://www.indelible.org/php/Log/guide.html
Jacques,
Quick question: at the moment it seems that logging happens before substiution in my where clause. So something like:
'conditions' => array('account_id = ?, $id)
is logged as
"WHERE account_id = ?"
Is it possible to set the logging after variable substitution?
exactly the same question
These are prepared statements, so you cannot log the final statement within PHP. Instead, you can use the Mysql Server Query log:
http://www.howtogeek.com/howto/database/monitor-all-sql-queries-in-mysql/
http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Alternatively you could change Connection.php:273 to log the values (here: $id) as well.
Guys is there any way to get query execution time using pear log?
Sure, but not using the vanilla version.
https://github.com/greut/php-activerecord/compare/gh133-profiling
Oh! Thank you so much! This one works perfectly!
(1-10/10)
Subject: Sql string
If possible, I would like to examine the sql string that php.activerecord generates. Where is the best place to intercept this?