Php 如何使用Phalcon Form删除结果集
考虑以下代码表单文档Php 如何使用Phalcon Form删除结果集,php,orm,phalcon,Php,Orm,Phalcon,考虑以下代码表单文档 foreach (Robots::find("type='mechanical'") as $robot) { if ($robot->delete() == false) { echo "Sorry, we can't delete the robot right now: \n"; foreach ($robot->getMessages() as $message) { echo $messa
foreach (Robots::find("type='mechanical'") as $robot) {
if ($robot->delete() == false) {
echo "Sorry, we can't delete the robot right now: \n";
foreach ($robot->getMessages() as $message) {
echo $message, "\n";
}
} else {
echo "The robot was deleted successfully!";
}
}
使用Phalcon,可以通过单个操作(无需迭代)删除结果集。从delete()
删除结果集中的所有记录
$robots = Robots::find("type='mechanical'");
if($robots->delete()){
echo "The robots were deleted successfully!";
}
我想知道用这种方法删除记录是否会运行SQL两次?一次用于选择,另一次用于选择DELETE@LCB如果查看源代码,您可以看到Phalcon创建了一个事务,然后对
resultset
中的每个对象调用delete
,它仅在删除每个记录时提交事务。