1

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.

3
  • in the exception you have, check if there is parent exception with actual error message Commented Dec 30, 2012 at 17:37
  • Actually, ZF just throws an exception, no data is captured. Commented Dec 30, 2012 at 17:45
  • 1
    Zend\Db throws exception with useless message, but it is setting exception from PDO/MySQLi as previous: php.net/manual/en/exception.getprevious.php Commented Dec 30, 2012 at 18:40

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.