简体   繁体   English

找出mysqli查询字符串

[英]find out mysqli query string

short question, but apparently google nor php.net have no idea about this so I was curious if it is possible. 简短的问题,但显然google或php.net对此一无所知,所以我很好奇是否有可能。

Can you get the query string of an mysqli element? 您可以获取mysqli元素的查询字符串吗? I need it to make a proper error function 我需要它来执行适当的错误功能

$mysqli = new mysqli(....);
$mysqli->query('INSERT INTO test(value) VALUES ('.rand(1,10000).');');
// here how do i find out the query of the $mysqli object WITHOUT having 
// to save it before (i.e. using the actual $mysqli object)

Thanks! 谢谢!

Judging from http://www.php.net/manual/en/class.mysqli-result.php - you can't. http://www.php.net/manual/en/class.mysqli-result.php来看-您不能。

$mysqli->query() is a method call, which returns mysqli_result object, and looking at the above manual page, it contains no record of the query that was just executed to create it. $mysqli->query()是一个方法调用,它返回mysqli_result对象,并查看上面的手册页,它不包含刚刚执行的创建查询的记录。

Not sure I understand your question, but: 不确定我是否理解您的问题,但是:

$sql = "INSERT INTO test(value) VALUES ('.rand(1,10000).');";
$mysqli->query($sql);

...then, later in your scirpt, you can just reference $sql : ...然后,在以后的脚本中,您只需引用$sql

if($sql = '...'){...}

Etc. 等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM