Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like debugDumpParams in pdo settable to a string

Tags:

php

pdo

I am trying to create a useful email to myself on pdo mysql errors, I am looking at "debugDumpParams", but sadly for some reason it just dumps the info right on the screen, you need to use output control functions to set it to a string which i don't quite understand.

Is there anything like that, that is settable to a string easily?

like image 603
NaughtySquid Avatar asked Mar 03 '14 21:03

NaughtySquid


1 Answers

The debugDumpParams() method writes to standard output. You can use an output buffer to capture standard output into a string. The following code works for me, based on one of the comments to imagepng() in the online manual :

function pdo_debugStrParams($stmt) {
  ob_start();
  $stmt->debugDumpParams();
  $r = ob_get_contents();
  ob_end_clean();
  return $r;
}

// omitted: connect to the database and prepare a statement
echo '<pre>'.htmlspecialchars(pdo_debugStrParams($stmt)).'</pre>';
like image 161
Damian Yerrick Avatar answered Sep 19 '22 18:09

Damian Yerrick