【问题标题】:Syntax error on SHOW TABLES LIKESHOW TABLES LIKE 上的语法错误
【发布时间】:2016-05-03 05:16:38
【问题描述】:

我不明白为什么在这个查询中显示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 ''User_notifications'':

<?php
include 'constants.php';
$username=$_POST['username'];
$notiftable=$username.'_notifications';
$con=new mysqli('',databaseuser,databasepassword,database);
if($con)
{
    $q="SHOW TABLES LIKE '$notiftable'";

【问题讨论】:

    标签: mysql php-5.5


    【解决方案1】:

    您的表名User_notifications 被双重转义(即它被转义两次)。这很可能会发生,因为 PHP 函数已经在转义它,而您正在第二次转义。尽量不要自己转义表名,即:

     $q = "SHOW TABLES LIKE $notiftable";
    

    【讨论】:

    • 没关系,错误来自另一个查询。我是菜鸟。
    • @Alexiy 你是说''User_notifications'' 从来没有造成过问题吗?
    • 其实User_notifications不加引号会报错。
    猜你喜欢
    • 2011-08-02
    • 2017-07-10
    • 2013-05-29
    • 2012-01-21
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    相关资源
    最近更新 更多