致命错误:未捕获的异常 'PDOException',消息为 'SQLSTATE[42000]: [英] Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:

查看:146
本文介绍了致命错误:未捕获的异常 'PDOException',消息为 'SQLSTATE[42000]:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,我正在计算行数,但它显示了这个错误..

I have a query where I am counting rows but it's showing this error..

致命错误:未捕获的异常 'PDOException' 带有消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'from=?AND to=?'在 C:\wamp\www\network\profile.php 的第 1 行'第 38 行

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'from=? AND to=?' at line 1' in C:\wamp\www\network\profile.php on line 38

( ! ) PDOException: SQLSTATE[42000]: 语法错误或访问冲突:1064 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'from=?AND to=?'在 C:\wamp\www\network\profile.php 第 1 行的第 38 行

( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'from=? AND to=?' at line 1 in C:\wamp\www\network\profile.php on line 38

这是我的代码:

$sql_check_friend = "SELECT COUNT(*) FROM connection_request WHERE from=:me AND"; 
$sql_check_friend .= "to=:friend";
    
$sth = $db->prepare($sql_check_friend);
$sth->bindParam(":me", $me);
$sth->bindParam(":friend", $pageuserid);
$sth->execute();

$count = $sth->fetchColumn();

if($count > 0){
echo "REQUEST SENT";
}else{
echo "NOT SENT";
}

我不知道出了什么问题..

I can't figure out what's wrong..

推荐答案

from 是一个 保留字.它必须在您的查询中转义:

from is a reserved word. It must be escaped in your query:

 SELECT ... WHERE `from` := ...
                  ^--  ^--- 

to 也是如此——它也是一个保留字.

And ditto for to as well - it's a reserved word too.

这篇关于致命错误:未捕获的异常 'PDOException',消息为 'SQLSTATE[42000]:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆