PDO和ON DUPLICATE KEY UPDATE

时间:2016-04-13 09:47:37

标签: mysql pdo

我想在此功能中设置ON DUPLICATE KEY UPDATE。

我怎么能做到这一点?

public function insert($table, $values) {           

    try {

        foreach ($values as $key => $value)
            $field_names[] = $key . ' = :' . $key;

        $sql = "INSERT INTO " . $table . " SET " . implode(', ', $field_names);

        $stmt = self::$PDO->prepare($sql);

        foreach ($values as $key => $value)
            $stmt->bindValue(':' . $key, $value);

        $stmt->execute();

    } catch (PDOException $exception) {

        die($exception->getMessage());

    }

}

有人能帮助我吗?

由于

0 个答案:

没有答案