【问题标题】:Performing a variable based sqlite3 update through php通过 php 执行基于变量的 sqlite3 更新
【发布时间】:2016-03-30 02:27:15
【问题描述】:

我正在尝试通过 PHP 脚本对 Sqlite3 数据库执行更新,但遇到了一对我不理解的错误。

PHP 警告:SQLite3::prepare(): Unable to prepare statement: 1, no such column: :column in C:\UwAmp\www\save.php on line 16, referer: http://localhost/Canvas.html

PHP 致命错误:未捕获的错误:在 C:\UwAmp\www\save.php:17\n 中调用成员函数 bindParam() 的布尔值:C:\n#0 {main}\n \UwAmp\www\save.php 第17行,referer:http://localhost/Canvas.html

这是我正在使用的 PHP 代码示例:

$url = $_POST['newURL'];
$name = $_POST['saveName'];
$index = $_POST['saveNum'];
$user = $_POST['username'];
$db = new SQLite3('Users.db');



$statement = $db->prepare("UPDATE Canvas_Saves SET ':column' = ':url' WHERE User = ':user'");
$statement->bindParam(':url', $url);
$statement->bindParam(':user', $user);
if($index ===1){
    $statement->bindParam(':column', 'Save1',SQLITE3_TEXT);
}
else if($index ===2){
    $statement->bindParam(':column', 'Save2',SQLITE3_TEXT);
}
else if($index ===3){
    $statement->bindParam(':column', 'Save3',SQLITE3_TEXT);
}
else if($index ===4){
    $statement->bindParam(':column', 'Save4',SQLITE3_TEXT);
}

$statement->execute();

第 16 行是 $db->prepare 语句。 我试图研究这个,但我没有任何运气。感谢您提供的任何帮助。

【问题讨论】:

  • 表结构如何?
  • Canvas_Saves表中相关字段为Save1、Save2、Save3、Save4。每个字段都是 TEXT 类型。

标签: php sqlite


【解决方案1】:

你可以用这个

$url = $_POST['newURL'];
$name = $_POST['saveName'];
$index = $_POST['saveNum'];
$user = $_POST['username'];
$db = new SQLite3('Users.db');
$col="";
if($index ===1){
    $col="Save1";
}
else if($index ===2){
    $col="Save2";
}
else if($index ===3){
    $col="Save3";
}
else if($index ===4){
    $col="Save4";
}
$statement = $db->prepare("UPDATE Canvas_Saves SET ".$col."=:url  WHERE User = :user ");
$statement->bindParam(":url", $url);
$statement->bindParam(":user", $user);
$statement->execute();

【讨论】:

  • 这给我留下了这个错误。 PHP Warning: SQLite3::prepare(): Unable to prepare statement: 1, near "=": syntax error in C:\\UwAmp\\www\\save.php on line 26, referer: http://localhost/Canvas.html 第 26 行指的是准备语句。
  • 我认为我传入的索引存在问题。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多