I'm trying to build a SQL object using ZF2's Db\\SQL.
Below is my code.
$sql = new Sql($this->database);
$predicate = new Where();
$query = $sql->select();
$query->from('sessions');
$query->columns(array('sessiondata'));
$query->where($predicate->equalTo('sessionid', $sessionId));
$query->where($predicate->greaterThan('expire', new Expression("NOW()")));
As you can read, I'm doing a session read.
The preparing is failing on the execute because of the [last] where property:
$query->where($predicate->greaterThan('expire', 'NOW()'));
Unfortunately, ZF2 doesn't tell me why it's failed, all I know is that Statement could not be executed
What am I doing wrong in the above?
I think that prepare is interpreting the thing as literally as it can, hence the presence of the mysql function Now()
is causing it to fail. How do I get past this?
EDIT: Actually, it's the execution that's failing.
Try debug the final query. You can use mysql query logger for that. In my.cnf(or my.ini) you set:
log = "C:/genquery.log"
OR
log = "/var/log/mysql/error.log"
depending on system.
Then reset mysql server and you can analyze what really happened.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.