PDOStatement::debugDumpParams
PDOStatement::debugDumpParams — Dumps the information contained in a prepared statement (PHP 5 >= 5.1.0, PECL pdo >= 0.9.0)
Description
Syntax
bool PDOStatement::debugDumpParams ( void )
Directly outputs the information of a prepared statement. This includes the SQL query being used, the number of parameters (Params), the list of parameters, parameter names, parameter type (paramtype) represented by an integer, key name or position, value, and position in the query (or -1 if the current PDO driver does not support it).
Tip: Similar to outputting results directly to the browser, you can use output control functions to capture the output of this function, and then (for example) save it to a string.
Only the parameters in the statement at this moment are printed. Additional parameters are not stored in the statement and thus are not output.
Return Value
No return value.
Examples
PDOStatement::debugDumpParams() Example with Named Parameters
<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
$sth->bindValue(':colour', $colour, PDO::PARAM_STR, 12);
$sth->execute();
$sth->debugDumpParams();
?>
The above example will output:
SQL: [96] SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour
Params: 2
Key: Name: [9] :calories
paramno=-1
name=[9] ":calories"
is_param=1
param_type=1
Key: Name: [7] :colour
paramno=-1
name=[7] ":colour"
is_param=1
param_type=2
PDOStatement::debugDumpParams() Example with Unnamed Parameters
<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$name = 'apple';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT);
$sth->bindValue(2, $colour, PDO::PARAM_STR);
$sth->execute();
$sth->debugDumpParams();
?>
The above example will output:
SQL: [82] SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?
Params: 2
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=1
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=2