PHP Class phprs\ezsql\Sql
How-to-use:
$db = new DB($dsn, $username, $passwd);
1. select
$res = Sql::select('a, b')
->from('table')
->leftJoin('table1')->on('table.id=table1.id')
->where('a=?',1)
->groupBy('b')->having('sum(b)=?', 2)
->orderBy('c', Sql::$ORDER_BY_ASC)
->limit(0,1)
->forUpdate()->of('d')
->get($db);
2. update
$rows = Sql::update('table')
->set('a', 1)
->where('b=?', 2)
->orderBy('c', Sql::$ORDER_BY_ASC)
->limit(1)
->exec($db)
->rows
3. insert
$newId = Sql::insertInto('table')
->values(['a'=>1])
->exec($db)
->lastInsertId()
4. delete
$rows = Sql::deleteFrom('table')
->where('b=?', 2)
->orderBy('c', Sql::$ORDER_BY_ASC)
->limit(1)
->exec($db)
->rows
Show file
Open project: caoym/phprs-restful
Class Usage Examples
Public Properties
Public Methods
Method |
Description |
|
deleteFrom ( string $table ) : WhereRule |
deleteFrom('table') => "DELETE FROM table" |
|
insertInto ( string $table ) : ValuesRule |
insertInto('table') => "INSERT INTO table" |
|
native ( string $str ) : Native |
Splice sql use native string(without escaping)
for example:
where('time>?', 'now()') => " WHERE time > 'now()' "
where('time>?', Sql::native('now()')) => " WHERE time > now() " |
|
replaceInto ( string $table ) : ValuesRule |
replaceInto('table') => "REPLACE INTO table" |
|
select ( $param0 = '*', $_ = null ) : FromRule |
select('column0,column1') => "SELECT column0,column1" |
|
update ( string $table ) : UpdateSetRule |
update('table') => "UPDATE table" |
|
Method Details
deleteFrom()
public static method
deleteFrom('table') => "DELETE FROM table"
insertInto()
public static method
insertInto('table') => "INSERT INTO table"
public static insertInto ( string $table ) : ValuesRule |
$table |
string |
|
return |
phprs\ezsql\rules\insert\ValuesRule |
|
native()
public static method
Splice sql use native string(without escaping)
for example:
where('time>?', 'now()') => " WHERE time > 'now()' "
where('time>?', Sql::native('now()')) => " WHERE time > now() "
replaceInto()
public static method
replaceInto('table') => "REPLACE INTO table"
select()
public static method
select('column0', 'column1') => "SELECT column0,column1"
public static select ( $param0 = '*', $_ = null ) : FromRule |
$param0 |
|
columns |
return |
phprs\ezsql\rules\select\FromRule |
|
update()
public static method
update('table') => "UPDATE table"
public static update ( string $table ) : UpdateSetRule |
$table |
string |
|
return |
phprs\ezsql\rules\update\UpdateSetRule |
|
Property Details
$ORDER_BY_ASC public static property
public static $ORDER_BY_ASC |
$ORDER_BY_DESC public static property
public static $ORDER_BY_DESC |