duanpan7011 2013-12-22 05:41
浏览 38
已采纳

SELECT查询的PDO语法错误

I have a basic query which gets all fields and exports the file but it keeps giving me an error. My code looks like this:

$array = ['users'];

foreach($array AS $i){
        $file = $i.'.sql';

        $stmt = $pdo->prepare("SELECT * FROM ? INTO OUTFILE ?");
        try {
            $stmt->execute(array($i,$file));
        } catch (PDOException $e) {
            $log .= $e -> getMessage().'........ 
 ';
        }
}

I keep getting this error how ever:

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 ''users' INTO OUTFILE 'users.sql'' at line 1.

What is the correct syntax for this ?

  • 写回答

2条回答 默认 最新

  • dpc57092 2013-12-22 05:56
    关注

    It(Syntax) should be the other way around

    SELECT * INTO OUTFILE ? FROM ?;
    

    See the documentation here

    EDIT :

    As JAL clarified, The table name cannot be passed as a parameter under a PreparedStatement. So your query should be like

    SELECT * INTO OUTFILE ? FROM users;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁
  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥15 Mabatis查询数据