We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[Phalcon Pdo] Strange error when I try to fetch result as column

I can't fetch result as column, but if directly use PDO then the result is right. And I got a strange error.

SQLSTATE[HY000]: General error: colno must be an integer

Provide minimal script to reproduce the issue

$list = $this->db
  ->fetchAll('SELECT id FROM tbl WHERE status = -2', \Phalcon\Db::FETCH_COLUMN);

// or

$result = $this->db->query('SELECT id FROM tbl WHERE status = -2');
$result->setFetchMode(\Phalcon\Db::FETCH_COLUMN);
$list = $result->fetchAll();

Details

edited Mar '18

Have you tried to bind the parameter?



648
edited Mar '18

Have you tried to bind parameter?

Yes, the same error.

$list = $this->db
  ->fetchAll('SELECT id FROM SMSBill WHERE status = ?', \Phalcon\Db::FETCH_COLUMN, [ -2 ]);
[email protected]:/opt/tvbill/src/cli$ ./app.php sms sync
SQLSTATE[HY000]: General error: colno must be an integer

#0 [internal function]: PDOStatement->setFetchMode(7, NULL)
#1 [internal function]: Phalcon\Db\Result\Pdo->setFetchMode(7)
#2 /opt/tvbill/src/cli/tasks/SmsTask.php(69): Phalcon\Db\Adapter->fetchAll('SELECT id FROM ...', 7, Array)
#3 [internal function]: SmsTask->syncAction(Array, Array)
#4 [internal function]: Phalcon\Cli\Dispatcher->callActionMethod(Object(SmsTask), 'syncAction', Array)
#5 [internal function]: Phalcon\Dispatcher->dispatch()
#6 /opt/tvbill/src/cli/app.php(40): Phalcon\Cli\Console->handle(Array)
#7 {main}
// PDO work
$list = $this->db->getInternalHandler()
  ->query('SELECT id FROM SMSBill WHERE status = -2')
  ->fetchAll(PDO::FETCH_COLUMN);

//  Array
//  (
//      [0] => 1
//      [1] => 3
//      [2] => 4
//      [3] => 5
//      [4] => 6
//      [5] => 7
//      [6] => 8
//      [7] => 9
//      [8] => 10
//      [9] => 11
//  )