javascript - PDO 和序列化

标签 javascript mysql serialization pdo jquery-ui-sortable

我在使用 PDO 将数据保存/更新到数据库时遇到问题。

此函数保存我的数据:

    function saveOrder($position,$id) {
    $sql = '
    UPDATE 
        '.DBPREFIX.'section_2 
    SET 
        order = ?
    WHERE 
        id = ?';
    $stmt = $this->db->prepare($sql);  
    $stmt->execute(array($position,$id));
    return var_dump($stmt->errorInfo());
}  

这是 sort_2.php:

$VAR_BACK = "../";
include($VAR_BACK."_config.php");
include($VAR_BACK."_config_db.php");
include($VAR_BACK."_functions.php");
include($VAR_BACK."_start.php");
include_once("../classes/helper.class.php");
$helper = new helper();

foreach ($_GET['item'] as $position => $item)
{
    $helper->saveOrder($position,$item);
}

这是我的前端 php 文件:

         <script>
// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
    ui.children().each(function() {
        $(this).width($(this).width());
    });
    return ui;
};

$(document).ready(function(){
    $("#sort tbody").sortable({
        helper: fixHelper,
        update : function () { 
                var data = $(this).sortable('serialize');
                //$('#info').text(data);
                $("#info").load("sort_2.php?"+data);
            } 
    }).disableSelection();
});

我总是收到这样的消息:

string(178) "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 'order = '2'
    WHERE 
        id = '1'' at line 4"  

第 4 行是:
订单=?

但我不知道这里可能出现什么错误。我尝试转换到(in​​t),我尝试了stripslashes,但没有任何效果。

在数据库中,列是:id = int(5) 和 order = varchar(10)

有什么建议吗?谢谢。

最佳答案

订单reserved word 。用反引号引用它:

$sql = '
UPDATE 
    '.DBPREFIX.'section_2 
SET 
    `order` = ?
WHERE 
    id = ?';

关于javascript - PDO 和序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363867/

相关文章:

javascript - ng2-bootstrap-modal 在 webpack 编译后不起作用

javascript - 查找并更改标签中文本的颜色

c# - 600K 记录的数据库或平面文件?

c# - 如何将选择查询的值存储在 web 服务的变量中?

c++ - 编译期间 boost xml 序列化失败

javascript - Three.js 根据坐标定位对象

javascript - 全局设置 Kendo UI 窗口值

mysql - 结合数据库查询

从服务器向客户端发送 HashMap 时发生 Java 空指针异常

c# - 使用 DataContractSerializer 自定义序列化