PDOStatement::debugDumpParams

PHP PDO 参考手册PHP PDO Reference Manual

PDOStatement::debugDumpParams — Dump an SQL prepared command (PHP 5 >= 5.1.0, PECL pdo >= 0.9.0)


Description

Syntax

bool PDOStatement::debugDumpParams ( void )

Directly prints out the information contained in a prepared statement. Provides the SQL query in use, the number of parameters (Params) used, the list of parameters, the parameter name, the parameter type (paramtype) expressed as an integer, the key name or position, the value, and the position in the query (or -1 if not supported by the current PDO driver).

This is a debugging feature that outputs data directly to the normal output.

Tip:Just like directly outputting the result 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 the current moment are printed. Extra parameters are not stored in the statement and therefore will not be output.


Return Values

No return value.


Examples

PDOStatement::debugDumpParams() example with named parameters

<?php
/* 通过绑定 PHP 变量执行一条预处理语句 */
$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

/* 通过绑定 PHP 变量执行一条预处理语句 */
$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

PHP PDO 参考手册PHP PDO Reference Manual

Other Extensions