public function testUpdate() { $b2 = new \b2\B2(); $expected = new \b2\query\Update('user'); $expected->where(['a' => 'b']); $actual = $b2->update('user', ['a' => 'b']); $this->assertEquals($expected, $actual); $expected = new \b2\query\Update('user'); $expected->where('hello = "world"'); $actual = $b2->update('user', 'hello = "world"'); $this->assertEquals($expected, $actual); }
<?php require_once __DIR__ . '/../autoload.php'; require_once __DIR__ . '/../tests/mock/Quote.php'; $quote = new b2\tests\mock\Quote(); $b2 = new b2\B2(); echo $b2->update('user')->set('money', 10)->where('id', 1)->toString($quote), "\n"; echo $b2->update('user')->set(['money' => 10])->where(['id' => 1])->toString($quote), "\n"; echo $b2->update('user')->set('`money` = ?', [10])->where('`id` = ?', [1])->toString($quote), "\n"; echo $b2->update('user')->set('`money` = :money', [':money' => 10])->where('`id` = :id', [':id' => 1])->toString($quote), "\n"; echo $b2->update('user')->set("`money` = '10'")->where("`id` = '1'")->toString($quote), "\n"; echo $b2->update('user')->set('`money` = `money` - ?', [20])->set(['vip' => 1])->set(['bannedUntil' => null])->set($b2->sql('field = ?', [10]))->where('id', 2)->where('`id` OR `uid`')->toString($quote) . "\n";