Get Last Executed Query in PHP PDO

<?php class MyPDOStatement extends PDOStatement { protected $_debugValues = null; protected function __construct() { // need this empty construct()! } public function execute($values=array()) { $this->_debugValues = $values; try { $t = parent::execute($values); // maybe do some logging here? } catch (PDOException $e) { // maybe do some logging here? throw $e; } return $t; } … Read more

Getting a PHP PDO connection from a mysql_connect()?

Both extensions internally use EG(persistent_list) to store the persistent connection handle. But they create different hashes/keys for this list, so they can’t find entries of the respective other extension. The mysql extension creates keys of the form “mysql_<host&port>_<user>…” while pdo builds “PDO:DBH:DSN=<dsn>:<user>:….”. The hashes are used almost like array-keys in a php script. (Over-)simplyfied example: … Read more

Retrieve (or simulate) full query from PDO prepared statement

I believe this is mentioned in the original question that was reference in this one. However there is actually supposed to be a method for retrieving this data. PDOStatement::debugDumpParams However it isn’t currently working as documented. There is a bug report and patch submitted for it here http://bugs.php.net/bug.php?id=52384 in case anyone is interested in voting … Read more

PDO::rowCount VS COUNT(*)

1st question: Using count COUNT(), internally the server(MySQL) will process the request differently. When doing COUNT(), the server(MySQL) will only allocate memory to store the result of the count. When using $row=$SQL->rowCount(); the server (Apache/PHP) will process the entire result set, allocate memory for all those results, and put the server in fetching mode, which … Read more