本文整理汇总了PHP中SQL::value方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::value方法的具体用法?PHP SQL::value怎么用?PHP SQL::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL::value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromSQL
public static function fromSQL($resource, $sql, $params = [])
{
$count = SQL::value(preg_replace(['(SELECT(.+)FROM)i', '(LIMIT\\s+\\d+\\s+)i', '(OFFSET\\s+\\d+\\s+)i'], ['SELECT COUNT(1) FROM', '', ''], $sql . ' '), $params, 0);
$page = Filter::with(["api.{$resource}.page", "api.page"], max(1, Request::get('page', 1)));
$limit = Filter::with(["api.{$resource}.limit", "api.limit"], max(1, Request::get('limit', 10)));
$page = min($page, ceil($count / $limit));
$offset = max(0, $page - 1);
$sql = "{$sql} LIMIT {$limit} OFFSET {$offset}";
return static::wrap($resource, SQL::each($sql, $params), $page, $limit, $count);
}
示例2: str_replace
$validations[] = 'required';
}
if (substr($e->Type, 0, 4) == 'enum') {
$validations[] = 'in_array:[' . str_replace("'", '"', substr($e->Type, 5, -1)) . ']';
}
$validations = implode(' | ', $validations);
$_s = str_repeat(' ', $ml - strlen($e->Field));
$d = " {$_s} = " . (is_numeric($e->Default) ? $e->Default : ($e->Default === null ? 'null' : "'{$e->Default}'"));
$valids[] = "'{$e->Field}' {$_s} => '{$validations}',\n";
$t = $e->Field == $last ? ';' : ',';
return "\${$e->Field}{$d}{$t} // {$e->Type}\n";
}, $fields));
if ($params) {
$params = " public {$params}";
}
$create = str_replace(["CREATE TABLE", "\n"], ["CREATE TABLE IF NOT EXISTS", "\n "], addslashes(SQL::value("show create table {$table}", [], 1)));
$valids = rtrim(implode(' ', $valids), "\n");
$date = date("Y-m-d H:i:s");
$model->code = <<<EOC
<?php
/**
* Model class for table {$table}
* Automatically generated on {$date}
*/
class {$model->name} extends Model {
const _PRIMARY_KEY_ = '{$table}.{$primary}';
{$params}
示例3: count
public static function count($where_sql = false, $params = [])
{
return (int) SQL::value('SELECT COUNT(1) FROM ' . static::persistenceOptions('table') . ($where_sql ? " where {$where_sql}" : ''), $params);
}