有没有办法查看准备好的查询,因为它将在数据库上执行? [重复]

时间:2021-06-12 09:06:50

Possible Duplicate:
PDO Prepared Statements

可能重复:PDO准备的声明

I'm using the mysqli extension in PHP and I'm wondering, is there possibly any way to see a prepared query as it will be executed on the server, e.g. The query is something like this

我在PHP中使用mysqli扩展,我想知道,有没有办法看到准备好的查询,因为它将在服务器上执行,例如查询是这样的

select * from table1 where id = ? and name = ?

but I want to see the query after the values are filled in, like this:

但我希望在填写值后查看查询,如下所示:

select * from table1 where id = 20 and name = "John"

4 个解决方案

#1


2  

Duplicate of PDO Prepared Statements

PDO准备声明重复

Short answer: no. A prepared query will never be converted to the query you expect. It's executed directly by the database server. You can use mysql's query log or PDO's undocumented function debugDumpParams, but both are just approximations.

简答:不。准备好的查询永远不会转换为您期望的查询。它由数据库服务器直接执行。您可以使用mysql的查询日志或PDO的未记录的函数debugDumpParams,但两者都只是近似值。

#2


7  

Turn on mysql query logging and it will log all queries to a text file for you to review.

打开mysql查询日志记录,它会将所有查询记录到文本文件*您查看。

#3


0  

See it where? If it's your code you have the query and you have the prepared parameters, log them separately or replace in the original query string. If the binding will fail you will get an error, otherwise you should expect the same values to be "filled" in as you specified them.

看到它在哪里?如果您的代码是您的代码,并且您具有准备好的参数,请单独记录它们或替换原始查询字符串。如果绑定失败,您将收到错误,否则您应该期望在指定它们时“填充”相同的值。

#4


0  

Its the way most of the times I am debugging mysql quires:

它是大多数时候我调试mysql quires的方式:

$q = "select * from table1 where id = ".$id." and name = ".$name; echo $q;

$ q =“select * from table1 where id =”。$ id。“and name =”。$ name; echo $ q;

The output generates all variables assigned to the query.

输出生成分配给查询的所有变量。

Hope I understood you exactly, what you wanted.

希望我完全理解你,你想要什么。

#1


2  

Duplicate of PDO Prepared Statements

PDO准备声明重复

Short answer: no. A prepared query will never be converted to the query you expect. It's executed directly by the database server. You can use mysql's query log or PDO's undocumented function debugDumpParams, but both are just approximations.

简答:不。准备好的查询永远不会转换为您期望的查询。它由数据库服务器直接执行。您可以使用mysql的查询日志或PDO的未记录的函数debugDumpParams,但两者都只是近似值。

#2


7  

Turn on mysql query logging and it will log all queries to a text file for you to review.

打开mysql查询日志记录,它会将所有查询记录到文本文件*您查看。

#3


0  

See it where? If it's your code you have the query and you have the prepared parameters, log them separately or replace in the original query string. If the binding will fail you will get an error, otherwise you should expect the same values to be "filled" in as you specified them.

看到它在哪里?如果您的代码是您的代码,并且您具有准备好的参数,请单独记录它们或替换原始查询字符串。如果绑定失败,您将收到错误,否则您应该期望在指定它们时“填充”相同的值。

#4


0  

Its the way most of the times I am debugging mysql quires:

它是大多数时候我调试mysql quires的方式:

$q = "select * from table1 where id = ".$id." and name = ".$name; echo $q;

$ q =“select * from table1 where id =”。$ id。“and name =”。$ name; echo $ q;

The output generates all variables assigned to the query.

输出生成分配给查询的所有变量。

Hope I understood you exactly, what you wanted.

希望我完全理解你,你想要什么。