Beispiel #1
0
<?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";
Beispiel #2
0
<?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->select('user', 'id > ?', [10])->field('uid')->field('name')->field('xp')->toString($quote) . "\n";
echo $b2->select('user', 'id = ?', [10])->leftJoin('payment', 'payment.id = user.id')->field($b2->sql('SUM(payment.price * ?)', [10]), 'sum')->toString($quote) . "\n";
$mysql = new mysqli();
$selectObject = $b2->select('user', 'id > ?', [10])->leftJoin('payment', 'payment.id = user.id')->fields(['user.id', 'sum' => $b2->sql('SUM(payment.value)')])->orderBy('sum', 'DESC');
$selectSql = $selectObject->toString($quote);
echo $selectSql . "\n";
Beispiel #3
0
<?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->insert('user', [['id' => 1, 'name' => 'John']])->toString($quote) . "\n";
echo $b2->insert('user')->row(['id' => 1, 'name' => 'John'])->toString($quote) . "\n";
echo $b2->insert('user')->rows([['id' => 1, 'name' => 'John']])->toString($quote) . "\n";
echo $b2->insert('user', [['id' => 1, 'name' => 'John'], ['id' => 2, 'name' => 'Ivan']])->toString($quote) . "\n";
// or
echo $b2->insert('user')->row(['id' => 1, 'name' => 'John'])->row(['id' => 2, 'name' => 'Ivan'])->toString($quote) . "\n";
// or
echo $b2->insert('user')->rows([['id' => 1, 'name' => 'John'], ['id' => 2, 'name' => 'Ivan']])->toString($quote) . "\n";
echo $b2->insert('user', [['id' => 1, 'name' => 'John']])->onDuplicateKeyUpdate()->toString($quote) . "\n";
echo $b2->insert('user', [['id' => 1, 'name' => 'John', 'age' => 20]])->onDuplicateKeyUpdate('name')->onDuplicateKeyUpdate('age')->toString($quote) . "\n";
echo $b2->insert('user', [['id' => 1, 'name' => 'John', 'age' => 20]])->onDuplicateKeyUpdate(['name', 'age'])->toString($quote) . "\n";
echo $b2->insert('counter')->row(['name' => 'visits', 'count' => 1])->onDuplicateKeyUpdate(['count' => $b2->sql('`count` + VALUES(`count`)')])->toString($quote) . "\n";
Beispiel #4
0
 public function testSql()
 {
     $b2 = new \b2\B2();
     $this->assertEquals(new PlainSql('hello'), $b2->sql('hello'));
     $this->assertEquals(new PlainSql('hello ?', [new Constant(1)]), $b2->sql('hello ?', [1]));
 }