对表中的每条记录执行MySql查询

时间:2017-08-10 14:47:01

标签: php mysql

好的,我有一个问题:

.done

问题是此查询正在更新 UPDATE example_table SET some_column = :some_data, else_column = :else_data; asd_column = :asd_data, xyz_column = :xyz_data, abc_column = :abc_column, qwe_column = :qwe_column, fgh_column = :fgh_column, tyu_column = :tyu_column, bnm_column = :bnm_column WHERE id = :user LIMIT 1 $p->bindParam(':user', $this->id, PDO::PARAM_STR); $p->bindParam(':some_column', $this->some_column, PDO::PARAM_INT); $p->bindParam(':else_column ', $this->else_column, PDO::PARAM_STR); $p->bindParam(':asd_column ', $this->asd_column, PDO::PARAM_INT); $p->bindParam(':xyz_column', $this->xyz_column, PDO::PARAM_STR); $p->bindParam(':abc_column', $this->abc_column, PDO::PARAM_INT); $p->bindParam(':qwe_column', $this->qwe_column, PDO::PARAM_INT); $p->bindParam(':fgh_column', $this->fgh_column, PDO::PARAM_INT); $p->bindParam(':tyu_column', $this->tyu_column, PDO::PARAM_INT); $p->bindParam(':bnm_column', $this->bnm_column, PDO::PARAM_STR); 中的每条记录 当然,我检查它只执行一次 因为example_table是有效的,并且它被解析为查询 这是唯一的条件。

我不知道是什么导致了这个问题,任何建议,也许有人有类似的问题。

2 个答案:

答案 0 :(得分:2)

因为你的陈述中间有分号(靠近else_column = :else_data;

UPDATE  example_table
SET     some_column = :some_data,
        else_column = :else_data;
        asd_column = :asd_data,
        xyz_column = :xyz_data,
        abc_column = :abc_column,
        qwe_column = :qwe_column,
        fgh_column = :fgh_column,
        tyu_column = :tyu_column,
        bnm_column = :bnm_column
WHERE   id = :user LIMIT 1

将以

执行
UPDATE  example_table
SET     some_column = :some_data,
        else_column = :else_data;

虽然应该是这样的

UPDATE  example_table
SET     some_column = :some_data,
        else_column = :else_data,
        asd_column = :asd_data,
        xyz_column = :xyz_data,
        abc_column = :abc_column,
        qwe_column = :qwe_column,
        fgh_column = :fgh_column,
        tyu_column = :tyu_column,
        bnm_column = :bnm_column
WHERE   id = :user

答案 1 :(得分:1)

; ::

替换为假,

(注意:更新语句中的ORDER BYLIMIT 1是mysql扩展或错误。在任何一种情况下,都不保证受影响的行的顺序)

UPDATE  example_table
SET     some_column = :some_data,
        else_column = :else_data, -- << HERE!
        asd_column = :asd_data,
        xyz_column = :xyz_data,
        abc_column = :abc_column,
        qwe_column = :qwe_column,
        fgh_column = :fgh_column,
        tyu_column = :tyu_column,
        bnm_column = :bnm_column
WHERE   id = :user LIMIT 1
      ;