gpt4 book ai didi

php - 为什么我收到 "You have an error in your SQL syntax"错误?

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:08 24 4
gpt4 key购买 nike

我在准备 mysqli 语句时遇到以下错误。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' phone = ?, status = ?, 'date' between ? AND ? ORDER BY id DESC LIMIT ?' at line 1

mysqli 预处理语句:

$stmt = $mysqli->prepare("SELECT id,role,fullname,phone,email,balance,status,parent, date_format(date,'%d-%m-%Y %h:%i:%s %p') AS date FROM users WHERE id = ?, phone = ?, status = ?, 'date' between ? AND ? ORDER BY id DESC LIMIT ?");
if ( false===$stmt )
{
die('prepare() failed: ' . htmlspecialchars($mysqli->error));
}
$rc = $stmt->bind_param('iiissi',$duid,$dmobile,$dstatus,$sdatetime,$edatetime,$dlimit);
if ( false===$rc )
{
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}
$re = $stmt->execute();
if ( false===$re )
{
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
$stmt->store_result();
$stmt->bind_result($userid, $urn, $uname, $uphone, $uemail, $ubalance, $ustatus, $up, $udate);
$stmt->fetch();

最佳答案

WHERE 子句用 AND(或 OR)而不是逗号分隔。您还有另一个语法错误,您将列名 date 放在引号中。应该是蜱虫。引号用于字符串。

$stmt = $mysqli->prepare("SELECT id,role,fullname,phone,email,balance,status,parent, date_format(date,'%d-%m-%Y %h:%i:%s %p') AS date FROM users 
WHERE id = ? AND phone = ? AND status = ?
AND `date` between ? AND ? ORDER BY id DESC LIMIT ?");

关于php - 为什么我收到 "You have an error in your SQL syntax"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54969690/

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