Asf_Db_AbstractQueryBuilder::where


Description

public object where(string $columns, mixed $value [, string $operator = '='])

Parameters

columns

数据库字段名称

value

字段的值

operator

支持的操作符 =, !=, <, > , 默认值 =

Return Values

操作成功返回 Object, 失败返回 false

Examples

Example #1

<?php
use Asf\Db\QueryBuilder\Select;

$select = new Select();

$select->cols()
    ->from('test1')
    ->where('id', '100', '>')
    ->where('status', 2)
    ->unionAll()
    ->select()
    ->cols()
    ->from('test1')
    ->where('id', '50', '<');

// string(132) "[SQL] SELECT * FROM `test1` WHERE `id` > ? AND `status` = ? UNION ALL SELECT * FROM `test1` WHERE `id` < ? [BVALUES] 100 , 2 , 50"
var_dump($select->show());
$select->clear();

$select->cols('id, user')
    ->from('test1', 'a')
    ->where('sid', 1)
    ->limit(0, 1);

// string(78) "[SQL] SELECT id, user FROM `test1` a WHERE `sid` = ? LIMIT 0, 1 [BVALUES] 1"
var_dump($select->show());

Example #2 相同的效果

<?php
use Asf\Db;

$select = Db::QBS();

$select->cols()
    ->from('test1')
    ->where('id', '100', '>')
    ->where('status', 2)
    ->unionAll()
    ->select()
    ->cols()
    ->from('test1')
    ->where('id', '50', '<');

// string(132) "[SQL] SELECT * FROM `test1` WHERE `id` > ? AND `status` = ? UNION ALL SELECT * FROM `test1` WHERE `id` < ? [BVALUES] 100 , 2 , 50"
var_dump($select->show());
$select->clear();

$select->cols('id, user')
    ->from('test1', 'a')
    ->where('sid', 1)
    ->limit(0, 1);

// string(78) "[SQL] SELECT id, user FROM `test1` a WHERE `sid` = ? LIMIT 0, 1 [BVALUES] 1"
var_dump($select->show());