DB::DBAL

The World's Most Powerful Light-Weight DBAL

Where

where( string $where_clause [, mixed $arg, mixed $arg, ...] )

The where() method requires a $where_clause argument, and optional arguments to replace question marks (“?”) in the where clause.

1
2
3
4
5
// Statement Only
DB::MySQL()->table('myTable')->select()->where('1 = 1');
// With Optional Additional Arguments
DB::MySQL()->table('myTable')->select()->where('1 = ?', 1);

The advantage to additional arguments is that they will be automatically escaped. However, for flexibility, you will still need to use the appropriate database syntax for quoting strings, such as:

1
2
3
4
5
DB::MySQL()->table('myTable')->select()->where('column = "?"', $data);
// Multiple Additional Arguments
DB::MySQL()->table('myTable')->select()
->where('column = "?" AND column2 = "?"', $data1, $data2);

orWhere( string $where_clause [, mixed $arg, mixed $arg, ...] )

andWhere( string $where_clause [, mixed $arg, mixed $arg, ...] )

To add additional WHERE statements, you can append the orWhere() or the andWhere() methods:

1
2
3
4
5
DB::MySQL()->table('myTable')->select()
->where('column = "?"', $data)->orWhere('column2 = "?"', $data);
DB::MySQL()->table('myTable')->select()
->where('column = "?"', $data)->andWhere('column2 = "?"', $data);

resetWhere( void )

There is also a removeWhere() method that clears the current WHERE statement. After clearing the statement, you may use the where() method to start your new WHERE clause.

1
2
3
4
5
6
// Statement with a WHERE Clause
$stmt = DB::MySQL()->table('myTable')->select()
->where('column = "?"', $data)->orWhere('column2 = "?"', $data);
// Remove WHERE clause
$stmt->removeWhere();