0

I want to execute a simple query:

SELECT DATEDIFF(now(), '2015-02-05');

How to execute this query in Zend Framework 1.x?

$sql = "SELECT DATEDIFF(now(), '2015-02-05')";
$db->fetchRow($sql);

or

$sql = "SELECT DATEDIFF(now(), '2015-02-05')";
$db->fetchRow($sql);

I checked the Zend manual, there are some other functions like fetchCol(), but in my project, there is no such a method, just have fetchAll(), fetchRow().

I am actually using a Zend Framework extension which is built upon Zend Framework, and it is in the 'lib' folder of the project. I guess this is why I can only use fetchAll(), fetchRow().

Anyone know how to execute such a simple query in Zend Framework?

halfer
  • 19,824
  • 17
  • 99
  • 186
NeoGeo
  • 49
  • 1
  • 6

1 Answers1

0

to get value from current position

    $sql = "SELECT DATEDIFF(now(), '2015-02-05') as dd";
    $r = $db->query($sql)->fetchColumn();

result: 346


to get array from current position

    $sql = "SELECT DATEDIFF(now(), '2015-02-05') as dd";
    $r = $db->query($sql)->fetch();

result: ['dd':346]


to get object from current position

    $sql = "SELECT DATEDIFF(now(), '2015-02-05') as dd";
    $r = $db->query($sql)->fetchObject('stdClass');

result: {'dd':346}


to get all rows

    $sql = "SELECT DATEDIFF(now(), '2015-02-05') as dd";
    $r = $db->query($sql)->fetchAll();

result: [0:['dd':346]]

Max P.
  • 5,579
  • 2
  • 13
  • 32