我正在使用 POST 将 JSOn 发送到 PHP Web 服务
JSON:
{"mDel":"NULL","mType":"text","mUserId":4,"lLong":"(null)","mPrivacy":1,"lLat":"(null)","mDate":"2012-13-25 13:13:25","mHeight":"NULL","mDescription":"Test","mPhoneUniqueKey":"425062012131325","mMedia":"4_2_20121325011325.png","lName":"Apple Store, San Francisco"}
PHP:
$request = Slim::getInstance()->request();
$moment = json_decode($request->getBody());
$sql = "INSERT INTO mymo_moment (profile_id, description, media, locationName, lat, long, mDate, privacy, type, iPhoneUniqueID, deleted, height)
VALUES (:mUserId, :mDescription, :mMedia, :lName, :lLat, :lLong, :mDate, :mPrivacy, :mType, :mPhoneUniqueKey, :mDel, :mHeight)";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam(":mUserId", $moment->mUserId);
$stmt->bindParam(":mDescription", $moment->mDescription);
$stmt->bindParam(":mMedia", $moment->mMedia);
$stmt->bindParam(":lName", $moment->lName);
$stmt->bindParam(":lLat", $moment->lLat);
$stmt->bindParam(":lLong", $moment->lLong);
$stmt->bindParam(":mDate", $moment->mDate);
$stmt->bindParam(":mType", $moment->mType);
$stmt->bindParam(":mPrivacy", $moment->mPrivacy);
$stmt->bindParam(":mPhoneUniqueKey", $moment->mPhoneUniqueKey);
$stmt->bindParam(":mDel", $moment->mDel);
$stmt->bindParam(":mHeight", $moment->mHeight);
$stmt->execute();
echo($stmt);
$moment->id = $db->lastInsertId();
$db = null;
echo json_encode($moment);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
而且我收到以下错误,我已经看过这个,但我无法弄清楚我做错了什么,任何帮助都会很棒!
错误:
{"error":{"text":SQLSTATE[42000]: Syntax error or access violation: 1064 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 'long, mDate, privacy, type, iPhoneUniqueID, deleted, height)
VALUES ('4',' at line 1}}