本文整理匯總了PHP中Foo::query方法的典型用法代碼示例。如果您正苦於以下問題:PHP Foo::query方法的具體用法?PHP Foo::query怎麽用?PHP Foo::query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Foo
的用法示例。
在下文中一共展示了Foo::query方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_batch
function test_batch()
{
// Clear existing records
$this->assertTrue(DB::execute('delete from foo'));
// Test batch array of insertions
$this->assertTrue(Foo::batch(array(array('id' => 1, 'name' => 'One'), array('id' => 2, 'name' => 'Two'), array('id' => 3, 'name' => 'Three'))));
$this->assertEquals(3, Foo::query()->count());
// Test closure batch
$this->assertTrue(Foo::batch(function () {
// Update an existing item
$one = new Foo(1);
$one->name = 'Joe';
if (!$one->put()) {
$f->error = $one->error;
return false;
}
// Add a new one too
$four = new Foo(array('name' => 'Four'));
if (!$four->put()) {
$f->error = $four->error;
return false;
}
}));
$this->assertEquals(4, Foo::query()->count());
$one = new Foo(1);
$this->assertEquals('Joe', $one->name);
// Test rollback on false
$this->assertFalse(Foo::batch(function () {
$five = new Foo(array('name' => 'Five'));
$five->put();
return false;
}));
$this->assertEquals(4, Foo::query()->count());
}