function updateThisMemberInterests($PDOdbObject, $memberId, $interests)
{
try
{
$intId = 0;
$upInt = $connectionObject->prepare("UPDATE `member_interest` SET (`interest_id`) VALUES (:intId)");
$upInt->bindParam(':intId', $intId, PDO::PARAM_INT);
foreach($interests as $intId)
{
$upInt->execute();
}
$affected_rows = $upInt->rowCount();
return $affected_rows;
}
catch (PDOException $e)
{
echo "There was a problem connecting to this database.";
$e->getMessage();
}
}
我的数据库设置功能指定: PDO :: ATTR_EMULATE_PREPARES =>假, PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION
但是我没有得到任何东西,除了我在Catch中的回音信息。
必须错误地解释教程的说明 - 有人能告诉我它是什么吗?
答案 0 :(得分:1)
ok - 由于错误处理已打开,我发现了几个问题,特别是我混合了INSERT和UPDATE语法。最后,我通过删除现有兴趣并插入新兴趣的交易解决了问题。这很有效。
这是我的代码:
function updateThisMemberInterests($PDOdbObject, $memberId, $interests)
{
if ($interests != 0)
{
try
{
//begin transaction
$PDOdbObject->beginTransaction();
$delInts = "DELETE FROM `member_interest` WHERE `member_id` = $memberId";
$PDOdbObject->exec($delInts);
$intId = 0;
$upInt = $PDOdbObject->prepare( "INSERT INTO member_interest (`member_id`,`interest_id`) VALUES ($memberId, :interest_id)" );
$upInt->bindParam(':interest_id', $intId, PDO::PARAM_INT);
foreach($interests as $intId)
{
$upInt->execute();
}
//commit
$PDOdbObject->commit();
$affected_rows = $upInt->rowCount();
return $affected_rows;
}
catch (PDOException $e)
{
echo "There was a problem - rolling back this transaction.";
//rollback transaction
$PDOdbObject->rollBack();
echo $e->getMessage();
}
}//more than zero interests changed
}