Skip to content

Instantly share code, notes, and snippets.

@zgia
Created August 5, 2020 14:05
Show Gist options
  • Save zgia/08581e652c8e43e7aed13337f60551d3 to your computer and use it in GitHub Desktop.
Save zgia/08581e652c8e43e7aed13337f60551d3 to your computer and use it in GitHub Desktop.
PDOStatement::debugDumpParams
<?php
try {
$dbh = new PDO('mysql:host=127.0.0.1;dbname=mysql', 'root', 'pwd');
$host = 'localhost';
$sth = $dbh->prepare('SELECT * FROM user WHERE Host = :host');
$sth->bindValue(':host', $host, PDO::PARAM_STR);
$sth->execute();
ob_start();
$sth->debugDumpParams();
$dump = ob_get_contents();
ob_end_clean();
$sth = null;
$dbh = null;
$tmp = explode("\n", $dump);
var_dump(substr($tmp[1], stripos($tmp[1], 'SELECT')));
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . PHP_EOL;
}
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment