本文整理汇总了PHP中PDO::tableName方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::tableName方法的具体用法?PHP PDO::tableName怎么用?PHP PDO::tableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::tableName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareSQL
/**
* Returns generic SQL query that can be adaptated by child classes.
*
* @version 0.1.5
* @since 0.1.5
* @param array $fields Fields to be selected.
* @param bool $count Shows if the SQL should be generated for COUNT() variant.
* @return string SQL query.
*/
protected function prepareSQL($fields, $count = false)
{
$tables = array();
// generates tables list for current qeury
if (isset($this->filter)) {
$tables = $this->filter->getTables();
}
// adds default table
if (!in_array($this->table, $tables)) {
$tables[] = $this->table;
}
// prepares tables names
foreach ($tables as &$name) {
$name = $this->db->tableName($name);
}
// WHERE clause
if (isset($this->filter)) {
$where = ' WHERE ' . $this->filter->__toString();
} else {
$where = '';
}
// ORDER BY clause
if ($count || empty($this->orderBy)) {
$orderBy = '';
} else {
$orderBy = array();
foreach ($this->orderBy as $criterium) {
switch ($criterium['order']) {
case POT::ORDER_ASC:
$orderBy[] = $criterium['field'] . ' ASC';
break;
case POT::ORDER_DESC:
$orderBy[] = $criterium['field'] . ' DESC';
break;
}
}
$orderBy = ' ORDER BY ' . implode(', ', $orderBy);
}
return 'SELECT ' . implode(', ', $fields) . ' FROM ' . implode(', ', $tables) . $where . $orderBy . $this->db->limit($this->limit, $this->offset);
}
示例2: getSchemaInfo
/**
* Returns OTServ database information.
*
* <p>
* Especialy currently only schema version is available (via <i>'version'</i> key).
* </p>
*
* @version 0.1.6
* @since 0.1.6
* @return array List of schema settings.
* @throws PDOException On PDO operation error.
* @example examples/schema.php schema.php
*/
public function getSchemaInfo()
{
$info = array();
// generates associative array
/// FIXME: 0.2.0 - Use PDO::FETCH_KEY_ASSOC
foreach ($this->db->query('SELECT ' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('schema_info')) as $row) {
$info[$row['name']] = $row['version'];
}
return $info;
}