PDOStatement::debugDumpParams
(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
PDOStatement :: debugDumpParams - 转储SQL准备的命令
描述
public void PDOStatement::debugDumpParams ( void )
直接在输出上转储准备好的语句中包含的信息。它将提供使用中的SQL查询,使用的参数数量(Params),参数列表及其关键名称或位置,它们的名称以及它们在查询中的位置(如果PDO驱动程序支持它,否则它将是-1),键入(param_type)作为整数与布尔值is_param。
这是一个调试功能,它将数据直接转储到正常输出。
注意点:
与任何将结果直接输出到浏览器的东西一样,输出控制函数可用于捕获此函数的输出,并将其保存为字符串(作为一个例子)。
这只会在转储时转储语句中的参数。额外的参数不存储在语句中,并且不显示。
返回值
没有返回值。
示例
示例#1具有命名参数的PDOStatement :: debugDumpParams()示例
<?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();
?>
上面的例子将输出:
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
示例#2带有未命名参数的PDOStatement :: debugDumpParams()示例
<?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();
?>
上面的例子将输出:
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
扩展内容
- PDO :: prepare() - 准备执行语句并返回一个语句对象
- PDOStatement :: bindParam() - 将参数绑定到指定的变量名称
- PDOStatement :: bindValue() - 将值与参数一一绑定
← PDOStatement::columnCount
PDOStatement::errorCode →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com