数据是json编码的。似乎总是失败并且错误,好像字符串没有被正确地转义,即使我已经尝试使用quote()
作为文档建议...而且mysql_real_escape_string()
但似乎没有任何作用:S < / p>
如果我将$ data更改为'apa'而不是我的json,我得到:
PDO::errorInfo(): Array ( [0] => 42000 [1] => 1064 [2] => 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 ''\'apa\'')' at line 1 )
-
$data = json_encode($jsonStoreArr, JSON_HEX_APOS | JSON_HEX_QUOT);
$stmt = $pdo->prepare("INSERT INTO _mytablename (movie_id, cached_data) VALUES (:id, :data) ON DUPLICATE KEY UPDATE cached_data = values(:data)");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':data', $data, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->errorCode() !== '00000') {
print_r($stmt->errorInfo());
}
答案 0 :(得分:0)
我在json字符串中urlencoded url然后只是这样做(下面),现在它可以工作!
$data = json_encode($jsonStoreArr);
$stmt = $pdo->prepare("INSERT INTO _mytablename (movie_id, cached_data) VALUES (:id, :data) ON DUPLICATE KEY UPDATE cached_data = :data");
$stmt->bindParam(':data', $data, PDO::PARAM_STR);