删除特定的MySQL数据库条目

时间:2013-07-19 15:37:24

标签: php mysql database

我正在尝试删除MYSQL数据库中的特定条目。

数据库:PhotoID,IDCount,UserID。

这是我根据ID删除照片的代码。

function delete($IdPhoto) {

$result = query("DELETE from photos WHERE IdPhoto='%d'", $IdPhoto);
if (!$result['error']) {
    // if no error occured, print out the JSON data of the 
    // fetched photo data
    print json_encode($result);
} else {
    //there was an error, print out to the iPhone app
    errorJson('Photo stream is broken');
}
}

这与iOS应用程序配对,该应用程序始终抓取当前的照片ID。按下按钮时,将触发API中的删除功能。这似乎不起作用。

以下查询有效(特定ID):

    $result = query("DELETE from photos WHERE IdPhoto=10");

任何帮助将不胜感激。目标是根据我们在iOS应用程序中获取的$ IdPhoto删除照片。

4 个答案:

答案 0 :(得分:1)

你试过这个:

     $result = mysql_query("DELETE from photos WHERE IdPhoto='$IdPhoto'  ");

你应该使用mysql_query

答案 1 :(得分:1)

试试这个:

$result = query("DELETE from photos WHERE IdPhoto={$IdPhoto}");

答案 2 :(得分:1)

..IdPhoto='%d'

应该是

..IdPhoto=%d

由于int不应包含quotes

答案 3 :(得分:0)

“=”只会比较两个int值或double值。确保您正在比较int类型。因此你的删除函数应该传递一个int,否则你可能需要像getIntvalue()这样的函数来提取int值。