PHP Класс 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
Показать файл
Открыть проект
Примеры использования класса
Открытые свойства
Открытые методы
Метод |
Описание |
|
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" |
|
Описание методов
deleteFrom()
публичный статический Метод
deleteFrom('table') => "DELETE FROM table"
public static deleteFrom ( string $table ) : WhereRule |
$table |
string |
|
Результат |
phprs\ezsql\rules\basic\WhereRule |
|
insertInto()
публичный статический Метод
insertInto('table') => "INSERT INTO table"
public static insertInto ( string $table ) : ValuesRule |
$table |
string |
|
Результат |
phprs\ezsql\rules\insert\ValuesRule |
|
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()
публичный статический Метод
replaceInto('table') => "REPLACE INTO table"
public static replaceInto ( string $table ) : ValuesRule |
$table |
string |
|
Результат |
phprs\ezsql\rules\replace\ValuesRule |
|
select()
публичный статический Метод
select('column0', 'column1') => "SELECT column0,column1"
public static select ( $param0 = '*', $_ = null ) : FromRule |
$param0 |
|
columns |
Результат |
phprs\ezsql\rules\select\FromRule |
|
update()
публичный статический Метод
update('table') => "UPDATE table"
public static update ( string $table ) : UpdateSetRule |
$table |
string |
|
Результат |
phprs\ezsql\rules\update\UpdateSetRule |
|
Описание свойств
$ORDER_BY_ASC публичное статическое свойство
public static $ORDER_BY_ASC |
$ORDER_BY_DESC публичное статическое свойство
public static $ORDER_BY_DESC |