Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP打印SQLite查询_Php_Sqlite_Bindvalue - Fatal编程技术网

用PHP打印SQLite查询

用PHP打印SQLite查询,php,sqlite,bindvalue,Php,Sqlite,Bindvalue,我正在使用PHP和SQLite3来管理一些网站会话,我遇到了一个无法返回结果的查询问题。问题是我想在执行execute命令之前打印查询,但我找不到方法 更具体地说,我使用bindValue生成查询,然后需要打印生成的语句或sqlite执行的查询。我的代码是这样的: if (($db = new SQLite3('/var2/db/core.db', SQLITE3_OPEN_READONLY)) == null) { return false; } $user = 'user1'; $d

我正在使用PHP和SQLite3来管理一些网站会话,我遇到了一个无法返回结果的查询问题。问题是我想在执行
execute
命令之前打印查询,但我找不到方法

更具体地说,我使用bindValue生成查询,然后需要打印生成的语句或sqlite执行的查询。我的代码是这样的:

if (($db = new SQLite3('/var2/db/core.db', SQLITE3_OPEN_READONLY)) == null)
{
    return false;
}
$user = 'user1';
$db_user_query = 'SELECT id FROM users WHERE username=:username';

$stmt = $db->prepare($db_user_query);
$stmt->bindValue(':username', $db->escapeString($user), SQLITE3_TEXT);
// Print the generated query
$result = $stmt->execute();
// Or print the queried statement.
编辑: 我想打印到日志,例如:

SELECT id FROM users WHERE username="user1"

感谢您的帮助。

您正在使用准备好的语句/占位符。使用这些查询值时,您不会手动转义查询值。这将有效地双重转义该值,如果该值包含任何sql元字符,则可能会导致“无行”结果。现在,您必须使用
sqlite\u fetch.*
functions/methodsThanks@Marc B中的一个函数来处理已生成但查询未自动处理的结果集,我删除了
escapeString()
函数。在这种情况下,问题仍然存在。@RiggsFolly我不清楚(我将编辑问题)。在获取结果之前,我想将要执行的查询(字符串“SELECT…”)打印到日志中。也许您应该发布给您带来问题的查询。如果使用PDO作为具有debugDumpParams(void)方法的包装器,则可以打印查询。但是你应该知道你在参数中输入了什么。。。但即使使用PDO,也必须先执行,然后才能检索转储。准备好的语句背后的全部含义是,完整的查询只有在执行之后才存在