문제

$remote_ip = $_SERVER["REMOTE_ADDR"];
        $today_date = $todaydate->format("Y-m-d H:i:s");
        $tomorrow_date = $tomorrowdate->format("Y-m-d H:i:s");

        $conditions['conditions'] = array('ipaddress = ? AND dateattempt > ? AND dateattempt < ?', $remote_ip, $today_date, $tomorrow_date);

        $attempts = self::all($conditions);
        //$attempts = self :: all(array('conditions' => array('ipaddress = ?',$_SERVER["REMOVE_ADDR"])));

/*          print_r($_SERVER); */
/*          print_r($today_date); */
/*          print_r($tomorrow_date); */

        echo self::connection()->last_query;

I have the following code above. What happens is I'm trying to print out the query so I can see if I did the query correctly. The query runs correctly but the command self::connection()->last_query prints the following:

SELECT * FROM `table_name` WHERE ipaddress = ? AND dateattempt > ? AND dateattempt < ?

The problem is it should be filling in the ? with the conditions but its not. How do I get it to show me the results with the ?'s filled in?

도움이 되었습니까?

해결책

last_query is the raw SQL. PHP ActiveRecord is using PDO's prepared statement so you won't see the actual query.

What you should do is using a logger. The values will be shown there (the code).

$log = Log::singleton('file', 'my.log'); //using PEAR Log
ActiveRecord\Config::instance()->set_logging(true);
ActiveRecord\Config::instance()->set_logger($log);

Example from: http://www.phpactiverecord.org/boards/4/topics/1119-re-show-last-sql-query

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top