本文整理匯總了PHP中Driver::query方法的典型用法代碼示例。如果您正苦於以下問題:PHP Driver::query方法的具體用法?PHP Driver::query怎麽用?PHP Driver::query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Driver
的用法示例。
在下文中一共展示了Driver::query方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: query
/**
* 事務查詢
* @param string $sql
*/
protected function query($sql)
{
try {
if ($this->driver->query($sql, null, true)) {
$status = true;
} else {
$status = false;
}
} catch (\Exception $e) {
$status = false;
}
return $status;
}
示例2: free
/**
* @param mixed $link
*/
private function free($link)
{
$query = $this->controller->getQuery($this->driver, $link);
if ($query) {
try {
$this->driver->query($link, $query->getExpression());
$this->active->attach($link, $query);
} catch (\Exception $err) {
$this->active->detach($link);
$query->reject($err);
}
} else {
$this->active->detach($link);
}
}
示例3: __construct
/**
* @param Driver $driver
* @param Table $table
* @param Query $query
* @param bool $asArray
*/
public function __construct(Driver $driver, Table $table, Query $query, $asArray = false)
{
$this->asArray = $asArray;
$this->table = $table;
$params = [];
$this->tableName = $table->getName();
if (!$this->asArray) {
$this->recordClasses = [$this->tableName => $table->getDatabase()->getClassMapper()->getClassForRecord($this->tableName)];
}
$sql = $query->getRawSql();
if ($sql === null) {
$sql = $driver->buildSQL($table, $query, $params);
$this->fetchStyle = \PDO::FETCH_NUM;
foreach ($table->getColumns() as $column) {
if ($column->isPrimaryKey()) {
$this->primaryKeyOrdinals[$this->tableName][$column->getOrdinal()] = true;
}
$this->columnOrdinalMap[$this->tableName][$column->getOrdinal()] = $column->getName();
}
$offset = count($table->getColumns());
foreach ($query->getJoins() as $join) {
if (isset($join['cardinality'])) {
$joinedTableName = $join['table'];
$joinedTable = $table->getDatabase()->getTable($joinedTableName);
$this->joinedTables[$joinedTableName] = $joinedTable;
if (!$this->asArray) {
$this->recordClasses[$joinedTableName] = $joinedTable->getDatabase()->getClassMapper()->getClassForRecord($joinedTableName);
}
foreach ($joinedTable->getColumns() as $column) {
if ($column->isPrimaryKey()) {
$this->primaryKeyOrdinals[$joinedTableName][$offset + $column->getOrdinal()] = true;
}
$this->columnOrdinalMap[$joinedTableName][$offset + $column->getOrdinal()] = $column->getName();
}
$this->cardinalities[$joinedTableName] = $join['cardinality'];
if ($join['cardinality'] === Query::CARDINALITY_ONE_TO_MANY) {
$this->properties[$joinedTableName] = $joinedTableName;
} else {
$this->properties[$joinedTableName] = array_keys($join['on']);
}
$offset += count($joinedTable->getColumns());
}
}
} else {
$this->fetchStyle = \PDO::FETCH_ASSOC;
$this->rawSql = true;
}
$this->result = $driver->query($sql, $params);
$this->fetchNextRow();
}
示例4: cacheQuery
/**
* @param int $timeout
* @param string $statement query statement
* @param array $vars [optional]
* @return Statement object
* @throws ConnectionException
*/
protected function cacheQuery($timeout, $statement, array $vars = null)
{
if ($this->cache !== null) {
$queryId = $this->cache->getQueryId($statement, $vars);
$st = $this->cache->read($queryId, $timeout);
if (!$st) {
// Cache miss
$this->debug("Cache miss!");
$tmpSt = $this->connection->query($statement, $vars);
$st = Cache::createCacheableEstatement($tmpSt);
$this->cache->write($queryId, $st, $timeout);
}
return $st;
} else {
user_error('No cache engine found!', E_USER_WARNING);
return $this->query($statement, $vars);
}
}
示例5: testAffectedRows
/**
* Tests Result->affectedRows()
*/
public function testAffectedRows()
{
$res = $this->driver->query("SELECT 1, 2");
$this->assertEquals(1, $res->affectedRows());
}
示例6: query
public function query(array $parameters = [])
{
return $this->driver->query($this->get(), $parameters + $this->parameters);
}