PHP fatal error : Uncaught exception 'PDOException' with message 'SQLSTATE[42000]

标签 php mysql sql

我的网站有错误。 错误:

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 'get FROM login WHERE user_id = '252' LIMIT 1' at line 1' in /home/tregolap/public_html/config/class/universal.class.php:110 Stack trace: #0 /home/tregolap/public_html/config/class/universal.class.php(110): PDOStatement->execute(Array) #1 /home/tregolap/public_html/ajaxify/profile/profile_banner.php(89): universal->isOnline('252') #2 /home/tregolap/public_html/profile.php(71): include_once('/home/tregolap/...') #3 {main} thrown in /home/tregolap/public_html/config/class/universal.class.php on line 110

universal.class.php代码为:

if ($user != $session) {
      $query = $this->db->prepare("
        SELECT MAX(login_id) AS get 
        FROM login WHERE user_id = :id LIMIT 1");
      $query->execute(array(":id" => $user));

个人资料横幅错误:

<?php
if($universal->isOnline($get_id)){
  echo "<span class='user_status'>online</span>";
}

请有人告诉我哪里出了问题,或者我是否需要针对该主题编辑更多代码,以便我使用完整信息对其进行编辑,

谢谢!

最佳答案

在您的 SQL 中,getreserved words in MySQL 之一.您可以将其更改为非保留字或在其周围加上引号/反引号。

if ($user != $session) {
  $query = $this->db->prepare("
    SELECT MAX(login_id) AS `get` 
    FROM login WHERE user_id = :id LIMIT 1");
  $query->execute(array(":id" => $user));

关于PHP fatal error : Uncaught exception 'PDOException' with message 'SQLSTATE[42000],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46898452/

相关文章:

PHP:当使用explode()两次时,如何自动增加

php - 按日期和时间以一小时为间隔对数据进行分组和统计

php - MySQL + PHP——用户身份验证级别

php - 如何分离php生成的按钮

php - 对现有 SQL 结果执行查询?从 SQL 结果的子集中查找结果

MySQL 替换字符以匹配 where 子句

sql - 您遵循什么 SQL 编码标准?

SQL 比较工具

sql - 是否可以在 PostgreSQL 中创建一个带有变量名的表?

php - Laravel-按升序和降序排列记录