"pdo::exec() or pdo::query()?" Code Answer

3

when using pdo::exec the result returned is not of an pdostatement but an integer of the rows affected.

when using pdo::query the result returned is a pdostatement.

so the answer is it depends on what you need to do with the data, if you need to run query and not do anything with the results, then you should use exec to execute the query, otherwise if you need the number of rows, the data returned you should use pdo::query and then use the results returned by the call.

  • http://www.php.net/manual/en/pdo.query.php
  • http://php.net/manual/en/pdo.exec.php

in regards to the bug there are several work around that you can take

  • install pdo_mysql
  • replace mysql_attr_init_command with 1002
  • update your php to the latest stable release where it has been passed and patched.

the second issue may have some issues on 64bit's os's and some windows configurations.

bug information: http://bugs.php.net/bug.php?id=47224

By tkone on April 14 2022

Answers related to “pdo::exec() or pdo::query()?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.