gpt4 book ai didi

php - 为什么 PDO debugDumpParams 截断查询

转载 作者:可可西里 更新时间:2023-11-01 07:34:52 24 4
gpt4 key购买 nike

我发现了同样的问题 here但是没有人回答,我在这里提供了更简单的例子,然后再问...

代码:

<?php
$dbh = new PDO('mysql:dbname=test;host=127.0.0.1', 'root');
$sth = $dbh->prepare("
SELECT '
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
This is a debug function, which dump directly the data on the normal output.
Tip:
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
'
");
$sth->execute();
$sth->debugDumpParams();

结果:

SQL: [835] 
SELECT '
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
This is a debug function, which dump directly the data on the normal output.
Tip:
As with anythi
Params: 0

为什么会发生,如何解决?
提前致谢!

最佳答案

我认为 debugDumpParams 完全是一个错误。事实上,它仅在标准输出中吐出数据!

所以无论如何我都不会使用它,为了日志记录的目的,要么为 mysql 启用一个通用日志,要么为 PDO 创建一个具有日志记录功能的包装器(这个解决方案更便携)。

关于php - 为什么 PDO debugDumpParams 截断查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29410151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com