0

POSTを使用してJSOnをPHPWebサービスに送信しています

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}}
4

1 に答える 1

1

longtype- これらの名前は、使用している RDBMS によってはキーワードとして扱われる場合があります。列名を変更するか、その名前をエスケープします。つまり、MySQL 型では"long"なくMSSQL 型で*long{grave-accent}long{grave-accent}

また、次の構文を使用してステートメントを準備し、パラメーターをバインドすることもできます。

$stmt = $db->prepare($sql);
$stmt->execute(array(
    ':mType'   => $moment->mType,
    ...
    ':mHeight' => $moment->mHeight
));
于 2012-06-25T12:36:22.667 に答える