Get a request from a prepared PDO report

Is there a way to get the request that was used to create the PDO Prepared approval object?

+48
php mysql pdo
Feb 11 '10 at 8:40
source share
4 answers
+33
Feb 11 '10 at 9:40
source share

If you don't mind expanding the default object \ PDO and \ PDOStatement, you might consider:

github.com/noahheck/E_PDOStatement

This PDO extension allows you to see the full query request as an example of what can be done at the database level. It uses regex to interpolate the associated parameters of your PDO statement.

Extending the default definition of \ PDOStatement, E_PDOStatement can offer this default enhancement without requiring you to change your normal workflow.

Disclaimer: I created this extension.

I just hope this helps someone else.

+10
May 16 '14 at
source share

Self-promotion: https://github.com/ellisgl/GeekLab-GLPDO2 You can display the expected request using the debugging method. I updated this recently.

0
May 03 '17 at 5:27 a.m.
source share

This procedure works. Since debugDumpParams () does not return output. Here is a little trick I developed.

// get the output before debugDumpParams() get executed $before = ob_get_contents(); //start a new buffer ob_start(); // dump params now $smt->debugDumpParams(); // save the output in a new variable $data $data = ob_get_contents(); // clean the output screen ob_end_clean(); // display what was before debugDumpParams() got executed printf("%s", $before); $statement = ""; // Now for prepared statements if (stristr($data, 'Sent SQL') !== false) { // begin extracting from "Sent SQL" $begin = stristr($data, 'Sent SQL'); // get the first ] square bracket $square = strpos($begin, "]"); // collect sql $begin = substr($begin, $square + 1); $ending = strpos($begin, "Params"); $sql = substr($begin, 0, $ending); $sql = trim($sql); // sql statement here $statement = $sql; } else { if (stristr($data, 'SQL') !== false) { $begin = stristr($data, 'SQL'); // get the first ] square bracket $square = strpos($begin, "]"); // collect sql $begin = substr($begin, $square + 1); $ending = strpos($begin, "Params"); $sql = substr($begin, 0, $ending); $sql = trim($sql); $statement = $sql; } } // statement here echo $statement; 

Hope this helps.

0
Oct. 14 '18 at 20:43
source share



All Articles