Hello all,
I am using rowCount() to test whether a certain query is succesful. If I run this code:
$del_cust_recipe = $this->connection->prepare("DELETE FROM custom_ingredients_to_recipe WHERE owner_id=:owner_id AND recipe_id=:recipe_id");
$res_cust_recipe = $this->connection->executePrepared($del_cust_recipe,array('owner_id'=>$this->user_id,'recipe_id'=>$recipe_id),array('owner_id' => \Phalcon\Db\Column::TYPE_INTEGER,'recipe_id' => \Phalcon\Db\Column::TYPE_INTEGER));
$affected = $res_cust_recipe->rowCount();
echo $affected;
exit;
$affected returns 1, indicating 1 row has been deleted. Which is correct, checking from the database. The query has executed was: DELETE FROM custom_recipes WHERE owner_id='28' AND recipe_id='33'
However, when I continue the code, to test in case 0 rows were affected (meaning nothing was deleted):
$del_cust_recipe = $this->connection->prepare("DELETE FROM custom_ingredients_to_recipe WHERE owner_id=:owner_id AND recipe_id=:recipe_id");
$res_cust_recipe = $this->connection->executePrepared($del_cust_recipe,array('owner_id'=>$this->user_id,'recipe_id'=>$recipe_id),array('owner_id' => \Phalcon\Db\Column::TYPE_INTEGER,'recipe_id' => \Phalcon\Db\Column::TYPE_INTEGER));
$affected = $res_cust_recipe->rowCount();
echo $affected;
if ($affected == 0)
{
echo "erroneous result"
exit;
}
echo $affected returns 0 (and thus erroneous result echoed), even when a DELETE query has been executed (I made sure the record was there in the table again)
This is very puzzling to me. The code is essentially the same. If I exited the code direclty, $affected is 1 (correct behaviour)....if I continue with the code and exited a few lines later, $affected is 0 (incorrect behaviour) ??
I double-checked whether an acutal row was deleted and I confirm that to be the case. So rowCount should still return 1. Am I overlooking something?
Thanks for your help! Alex