duanhao5038 2018-07-25 22:45
浏览 59

PHP PDO变量插入与SQLite不兼容[重复]

when I run the following:

$pdo = new PDO('sqlite:/path/to/database.db');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare('CREATE TABLE IF NOT EXISTS :user (id INTEGER PRIMARY KEY AUTOINCREMENT, time INTEGER NOT NULL, ping TEXT NOT NULL);');
$user = "me";
$stmt->execute(array('user' => $user));

I get the following error, referencing the :user part of the SQL:

PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 near ":user": syntax error in /datasql.php:21 Stack trace: #0 /datasql.php(21): PDO->prepare('CREATE TABLE IF...') #1 {main} thrown in /datasql.php on line 21

I can't find anything wrong with the SQL and if I run the command without the variable insertion, it runs fine.

What is causing this error? Thanks ahead!

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置