我一直在尝试修复过去30分钟内的SQL状态错误。 我在这做错了什么? 欢迎任何建议。
$statement=$conn->prepare("SELECT to.ipaddress as ipaddress, to.email as email, to.orderdate as orderdate, to.is_completed as is_completed, p.price as price from temporder to, products p WHERE to.productid = p.productid AND to.ipaddress=? AND to.orderdate=? ");
$statement->execute(array(
$_SERVER['REMOTE_ADDR'],
date('Y-m-d')
));
$statement->setFetchMode(PDO::FETCH_ASSOC);
完成错误
SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在正确的语法附近使用,产品p WHERE to.productid = p.productid AND to.ipaddress =' :: 1'和to.or'在第1行
答案 0 :(得分:4)
TO
(你用作ALIAS)在MySQL中是reserved word,你需要在反引号中包围它。
从查询的一部分......
e as price from temporder to, products p WHERE to
^^^^ //<----- That's a reserved word. !
将它们包裹在下方的反击下..
e as price from temporder `to`, products p WHERE to
答案 1 :(得分:2)