本文整理汇总了PHP中dibi::sql方法的典型用法代码示例。如果您正苦于以下问题:PHP dibi::sql方法的具体用法?PHP dibi::sql怎么用?PHP dibi::sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dibi
的用法示例。
在下文中一共展示了dibi::sql方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(DibiConnection $connection, $type, $sql = NULL)
{
$this->connection = $connection;
$this->type = $type;
$this->sql = trim($sql);
$this->time = -microtime(TRUE);
if ($type === self::QUERY && preg_match('#\\(?\\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
static $types = array('SELECT' => self::SELECT, 'UPDATE' => self::UPDATE, 'INSERT' => self::INSERT, 'DELETE' => self::DELETE);
$this->type = $types[strtoupper($matches[1])];
}
$rc = new ReflectionClass('dibi');
$dibiDir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
foreach (debug_backtrace(FALSE) as $row) {
if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) {
$this->source = array($row['file'], (int) $row['line']);
break;
}
}
dibi::$elapsedTime = FALSE;
dibi::$numOfQueries++;
dibi::$sql = $sql;
}
示例2: nativeQuery
/**
* Executes the SQL query.
* @param string SQL statement.
* @return DibiResult|int result set object (if any)
* @throws DibiException
*/
public final function nativeQuery($sql)
{
$this->connect();
if ($this->profiler !== NULL) {
$event = IDibiProfiler::QUERY;
if (preg_match('#\\s*(SELECT|UPDATE|INSERT|DELETE)#i', $sql, $matches)) {
static $events = array('SELECT' => IDibiProfiler::SELECT, 'UPDATE' => IDibiProfiler::UPDATE, 'INSERT' => IDibiProfiler::INSERT, 'DELETE' => IDibiProfiler::DELETE);
$event = $events[strtoupper($matches[1])];
}
$ticket = $this->profiler->before($this, $event, $sql);
}
dibi::$sql = $sql;
if ($res = $this->driver->query($sql)) {
// intentionally =
$res = new DibiResult($res, $this->config);
} else {
$res = $this->driver->getAffectedRows();
}
if (isset($ticket)) {
$this->profiler->after($ticket, $res);
}
return $res;
}
示例3: nativeQuery
/**
* Executes the SQL query.
* @param string SQL statement.
* @return Result|int result set object (if any)
* @throws Exception
*/
public final function nativeQuery($sql)
{
$this->connected || $this->connect();
\dibi::$sql = $sql;
$event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : NULL;
try {
$res = $this->driver->query($sql);
} catch (Exception $e) {
$event && $this->onEvent($event->done($e));
throw $e;
}
if ($res) {
$res = $this->createResultSet($res);
} else {
$res = $this->driver->getAffectedRows();
}
$event && $this->onEvent($event->done($res));
return $res;
}
示例4: nativeQuery
/**
* Executes the SQL query.
* @param string SQL statement.
* @return DibiResult|int result set object (if any)
* @throws DibiException
*/
public final function nativeQuery($sql)
{
$this->connect();
if ($this->profiler !== NULL) {
$event = IDibiProfiler::QUERY;
if (preg_match('#\\s*(SELECT|UPDATE|INSERT|DELETE)#i', $sql, $matches)) {
static $events = array('SELECT' => IDibiProfiler::SELECT, 'UPDATE' => IDibiProfiler::UPDATE, 'INSERT' => IDibiProfiler::INSERT, 'DELETE' => IDibiProfiler::DELETE);
$event = $events[strtoupper($matches[1])];
}
$ticket = $this->profiler->before($this, $event, $sql);
}
// TODO: move to profiler?
dibi::$numOfQueries++;
dibi::$sql = $sql;
dibi::$elapsedTime = FALSE;
$time = -microtime(TRUE);
if ($res = $this->driver->query($sql)) {
// intentionally =
$res = new DibiResult($res, $this->config);
} else {
$res = $this->driver->getAffectedRows();
}
$time += microtime(TRUE);
dibi::$elapsedTime = $time;
dibi::$totalTime += $time;
if (isset($ticket)) {
$this->profiler->after($ticket, $res);
}
return $res;
}
示例5: after
public function after($ticket, $res = NULL)
{
if (!isset(self::$tickets[$ticket])) {
throw new InvalidArgumentException('Bad ticket number.');
}
$ticket =& self::$tickets[$ticket];
$ticket[3] += microtime(TRUE);
list($connection, $event, $sql, $time) = $ticket;
dibi::$elapsedTime = $time;
dibi::$totalTime += $time;
if (($event & $this->filter) === 0) {
return;
}
if ($event & self::QUERY) {
try {
$ticket[4] = $count = $res instanceof DibiResult ? count($res) : '-';
} catch (Exception $e) {
$count = '?';
}
if (count(self::$fireTable) < self::$maxQueries) {
self::$fireTable[] = array(sprintf('%0.3f', $time * 1000), strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql, $count, $connection->getConfig('driver') . '/' . $connection->getConfig('name'));
if ($this->explainQuery && $event === self::SELECT) {
$tmpSql = dibi::$sql;
try {
$ticket[5] = dibi::dump($connection->setProfiler(NULL)->nativeQuery('EXPLAIN ' . $sql), TRUE);
} catch (DibiException $e) {
}
$connection->setProfiler($this);
dibi::$sql = $tmpSql;
}
if ($this->useFirebug && !headers_sent()) {
header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
header('X-Wf-dibi-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0');
header('X-Wf-dibi-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
$payload = json_encode(array(array('Type' => 'TABLE', 'Label' => 'dibi profiler (' . dibi::$numOfQueries . ' SQL queries took ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms)'), self::$fireTable));
foreach (str_split($payload, 4990) as $num => $s) {
$num++;
header("X-Wf-dibi-1-1-d{$num}: |{$s}|\\");
}
header("X-Wf-dibi-1-1-d{$num}: |{$s}|");
}
}
if ($this->file) {
$this->writeFile("OK: " . $sql . ($res instanceof DibiResult ? ";\n-- rows: " . $count : '') . "\n-- takes: " . sprintf('%0.3f', $time * 1000) . ' ms' . "\n-- driver: " . $connection->getConfig('driver') . '/' . $connection->getConfig('name') . "\n-- " . date('Y-m-d H:i:s') . "\n\n");
}
}
}
示例6:
translateArgs($args){$this->connected||$this->connect();return$this->translator->translate($args);}final
function
nativeQuery($sql){$this->connected||$this->connect();if($this->profiler!==NULL){$event=IDibiProfiler::QUERY;if(preg_match('#\s*(SELECT|UPDATE|INSERT|DELETE)#iA',$sql,$matches)){static$events=array('SELECT'=>IDibiProfiler::SELECT,'UPDATE'=>IDibiProfiler::UPDATE,'INSERT'=>IDibiProfiler::INSERT,'DELETE'=>IDibiProfiler::DELETE);$event=$events[strtoupper($matches[1])];}$ticket=$this->profiler->before($this,$event,$sql);}dibi::$sql=$sql;if($res=$this->driver->query($sql)){$res=$this->createResultSet($res);}else{$res=$this->driver->getAffectedRows();}if(isset($ticket)){$this->profiler->after($ticket,$res);}return$res;}function
示例7: nativeQuery
/**
* Executes the SQL query.
*
* @param string SQL statement.
* @return DibiResult|NULL result set object (if any)
* @throws DibiException
*/
public final function nativeQuery($sql)
{
$this->connect();
dibi::$numOfQueries++;
dibi::$sql = $sql;
dibi::$elapsedTime = FALSE;
$time = -microtime(TRUE);
dibi::notify($this, 'beforeQuery', $sql);
if ($res = $this->driver->query($sql)) {
// intentionally =
$res = new DibiResult($res, $this->config);
}
$time += microtime(TRUE);
dibi::$elapsedTime = $time;
dibi::$totalTime += $time;
dibi::notify($this, 'afterQuery', $res);
return $res;
}