本文整理汇总了PHP中JDatabaseDriver::getTableColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabaseDriver::getTableColumns方法的具体用法?PHP JDatabaseDriver::getTableColumns怎么用?PHP JDatabaseDriver::getTableColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDatabaseDriver
的用法示例。
在下文中一共展示了JDatabaseDriver::getTableColumns方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getColumns
/**
* Get table columns.
*
* @param string $table Table name.
*
* @return array Table columns with type.
*/
public function getColumns($table)
{
if (empty(self::$columnCache[$table])) {
self::$columnCache[$table] = $this->db->getTableColumns($table);
}
return self::$columnCache[$table];
}
示例2: getFields
/**
* Get the database columns.
*
* @return mixed An array of the field names, or false if an error occurs.
*
* @since K4.0
* @throws UnexpectedValueException
*/
public static function getFields()
{
if (static::$tbl_fields === null) {
// Lookup the fields for this table only once.
static::$tbl_fields = static::$db->getTableColumns(static::$tbl, false);
if (empty(static::$tbl_fields)) {
throw new UnexpectedValueException(sprintf('No columns found for %s table', static::$tbl));
}
}
return array_keys(static::$tbl_fields);
}
示例3: getFields
/**
* Get the columns from database table.
*
* @return mixed An array of the field names, or false if an error occurs.
*
* @since 11.1
* @throws UnexpectedValueException
*/
public function getFields()
{
static $cache = null;
if ($cache === null) {
// Lookup the fields for this table only once.
$name = $this->_tbl;
$fields = $this->_db->getTableColumns($name, false);
if (empty($fields)) {
throw new UnexpectedValueException(sprintf('No columns found for %s table', $name));
}
$cache = $fields;
}
return $cache;
}
示例4: getFields
/**
* Get the columns from database table.
*
* @return mixed An array of the field names, or false if an error occurs.
*
* @throws UnexpectedValueException
*/
public function getFields()
{
static $cache = array();
$name = $this->_tbl;
if (!isset($cache[$name])) {
// Lookup the fields for this table only once.
$fields = $this->_db->getTableColumns($name, false);
if (empty($fields)) {
throw new UnexpectedValueException(sprintf('No columns found for %s table', $name));
}
$cache[$name] = $fields;
}
return (array) $cache[$name];
}
示例5: getTableFields
/**
* Get the columns from a database table.
*
* @param string Table name. If null current table is used
*
* @return mixed An array of the field names, or false if an error occurs.
*/
public function getTableFields($tableName = null)
{
static $cache = array();
static $tables = array();
// Make sure we have a list of tables in this db
if (empty($tables)) {
$tables = $this->_db->getTableList();
}
if (!$tableName) {
$tableName = $this->_tbl;
}
if (!array_key_exists($tableName, $cache)) {
// Lookup the fields for this table only once.
$name = $tableName;
$prefix = $this->_db->getPrefix();
if (substr($name, 0, 3) == '#__') {
$checkName = $prefix . substr($name, 3);
} else {
$checkName = $name;
}
if (!in_array($checkName, $tables)) {
// The table doesn't exist. Return false.
$cache[$tableName] = false;
} elseif (version_compare(JVERSION, '3.0', 'ge')) {
$fields = $this->_db->getTableColumns($name, false);
if (empty($fields)) {
$fields = false;
}
$cache[$tableName] = $fields;
} else {
$fields = $this->_db->getTableFields($name, false);
if (!isset($fields[$name])) {
$fields = false;
}
$cache[$tableName] = $fields[$name];
}
}
return $cache[$tableName];
}
示例6: __construct
/**
* Object constructor to set table and key fields. In most cases this will
* be overridden by child classes to explicitly set the table and key fields
* for a particular database table.
*
* @param string $table Name of the table to model.
* @param mixed $key Name of the primary key field in the table or array of field names that compose the primary key.
* @param JDatabaseDriver $db JDatabaseDriver object.
*
* @since 11.1
*/
public function __construct($table, $key, $db)
{
$this->_tableName = $table;
if (is_array($key)) {
$this->_tbl_keys = $key;
$this->_tbl_key = $key;
$this->_tableKey = $key[key($key)];
} else {
$this->_tbl_key = $key;
$this->_tableKey = $key;
}
// Set all columns from table as properties
$columns = array();
$dbColumns = $db->getTableColumns('#__' . $table, false);
if (count($dbColumns) > 0) {
foreach ($dbColumns as $columnKey => $columnValue) {
$columns[$columnValue->Field] = $columnValue->Default;
}
$this->setProperties($columns);
}
parent::__construct($db);
}
示例7: getTableFields
/**
* Get the columns from a database table.
*
* @param string $tableName Table name. If null current table is used
*
* @return mixed An array of the field names, or false if an error occurs.
*/
public function getTableFields($tableName = null)
{
// Should I load the cached data?
$useCache = array_key_exists('use_table_cache', $this->config) ? $this->config['use_table_cache'] : false;
// Make sure we have a list of tables in this db
if (empty(self::$tableCache)) {
if ($useCache) {
// Try to load table cache from a cache file
$cacheData = FOFPlatform::getInstance()->getCache('tables', null);
// Unserialise the cached data, or set the table cache to empty
// if the cache data wasn't loaded.
if (!is_null($cacheData)) {
self::$tableCache = json_decode($cacheData, true);
} else {
self::$tableCache = array();
}
}
// This check is true if the cache data doesn't exist / is not loaded
if (empty(self::$tableCache)) {
self::$tableCache = $this->_db->getTableList();
if ($useCache) {
FOFPlatform::getInstance()->setCache('tables', json_encode(self::$tableCache));
}
}
}
// Make sure the cached table fields cache is loaded
if (empty(self::$tableFieldCache)) {
if ($useCache) {
// Try to load table cache from a cache file
$cacheData = FOFPlatform::getInstance()->getCache('tablefields', null);
// Unserialise the cached data, or set to empty if the cache
// data wasn't loaded.
if (!is_null($cacheData)) {
$decoded = json_decode($cacheData, true);
$tableCache = array();
if (count($decoded)) {
foreach ($decoded as $myTableName => $tableFields) {
$temp = array();
if (is_array($tableFields)) {
foreach ($tableFields as $field => $def) {
$temp[$field] = (object) $def;
}
$tableCache[$myTableName] = $temp;
} elseif (is_object($tableFields) || is_bool($tableFields)) {
$tableCache[$myTableName] = $tableFields;
}
}
}
self::$tableFieldCache = $tableCache;
} else {
self::$tableFieldCache = array();
}
}
}
if (!$tableName) {
$tableName = $this->_tbl;
}
// Try to load again column specifications if the table is not loaded OR if it's loaded and
// the previous call returned an error
if (!array_key_exists($tableName, self::$tableFieldCache) || isset(self::$tableFieldCache[$tableName]) && !self::$tableFieldCache[$tableName]) {
// Lookup the fields for this table only once.
$name = $tableName;
$prefix = $this->_db->getPrefix();
if (substr($name, 0, 3) == '#__') {
$checkName = $prefix . substr($name, 3);
} else {
$checkName = $name;
}
if (!in_array($checkName, self::$tableCache)) {
// The table doesn't exist. Return false.
self::$tableFieldCache[$tableName] = false;
} elseif (version_compare(JVERSION, '3.0', 'ge')) {
$fields = $this->_db->getTableColumns($name, false);
if (empty($fields)) {
$fields = false;
}
self::$tableFieldCache[$tableName] = $fields;
} else {
$fields = $this->_db->getTableFields($name, false);
if (!isset($fields[$name])) {
$fields = false;
}
self::$tableFieldCache[$tableName] = $fields[$name];
}
// PostgreSQL date type compatibility
if ($this->_db->name == 'postgresql' && self::$tableFieldCache[$tableName] != false) {
foreach (self::$tableFieldCache[$tableName] as $field) {
if (strtolower($field->type) == 'timestamp without time zone') {
if (stristr($field->Default, '\'::timestamp without time zone')) {
list($date, $junk) = explode('::', $field->Default, 2);
$field->Default = trim($date, "'");
}
}
//.........这里部分代码省略.........
示例8: getFields
/**
* Get table fields.
*
* @param string $table Table name.
*
* @return array
*/
public function getFields($table)
{
$columns = $this->db->getTableColumns($table);
return array_keys($columns);
}