使用php pdo查询不会更新

时间:2011-10-16 08:09:25

标签: php mysql pdo

我的第一个问题是:

$sql = "UPDATE application SET userid = ? WHERE appid = ? LIMIT 1";

我的第二个疑问是:

SELECT user.name,application.appid,application.userid,application.created,application.title,application.filesize,application.status,application.apptype 
FROM user,application 
WHERE application.appid = ? LIMIT 1

然后使用$statement->fetchObject()

存储第二个查询

问题是$statement->name总是bobapplication.userid是表useriduser的外键。如果我更改表userid中的application,请说10,查询2应该从新user上的表userid中获取名称,但是问题是,它一直告诉我$statement->namebob

if (isset($_POST['newowner']))
{
    $newowner = $_POST['newowner'];
    $sql = "SELECT COUNT(*) FROM user 
            WHERE userid = ? LIMIT 1";
    $statement = $db->prepare($sql);
    $statement->execute(array($newowner));

    if ($statement->fetchColumn() > 0)
    {
        $sql = "UPDATE application SET userid = ? 
                WHERE appid = ? LIMIT 1";
        $statement = $db->prepare($sql);
        $statement->execute(array($newowner,$_GET['appid']));
        $appdetail->msg = "Owners were successfully changed.";
        $appdetail->type = "success";
    }
    else
    {
        $appdetail->msg = "Could not find client by that userid or email.";
        $appdetail->type = "warning";
    }
}
$sql = "SELECT user.name,application.appid,application.userid,application.created,application.title,application.filesize,application.status,application.apptype 
        FROM user,application 
        WHERE application.appid = ? LIMIT 1";
$statement = $db->prepare($sql);
$statement->execute(array($_GET['appid']));
$app = $statement->fetchObject();

1 个答案:

答案 0 :(得分:0)

使用PDO,您应该能够确定UPDATE影响的行数。检查这是否与您希望在测试数据中修改的行数相对应。编辑:this是您需要的声明。