本文整理匯總了PHP中sDB::datatype方法的典型用法代碼示例。如果您正苦於以下問題:PHP sDB::datatype方法的具體用法?PHP sDB::datatype怎麽用?PHP sDB::datatype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sDB
的用法示例。
在下文中一共展示了sDB::datatype方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
/**
* Initializes the ShoppDatabaseObject with functional necessities
*
* A ShoppDatabaseObject tracks meta data relevant to translating PHP object
* data into SQL-ready data. This is done by reading and caching the
* table schema so the properties and their data types can be known
* in order to automate query building.
*
* The table schema is stored in an array structure that contains
* the columns and their datatypes. This structure is cached as the
* current data_model setting. If a table is missing from the data_model
* a new table schema structure is generated on the fly.
*
* @author Jonathan Davis
* @since 1.0
*
* @param string $table The base table name (without prefixes)
* @param string $key (optional) The column name of the primary key
* @return boolean True if init was successful, otherwise false
**/
public function init($table, $key = null)
{
if (is_null($key)) {
$key = 'id';
}
$Settings = ShoppSettings();
// So we know what the table name is
if (!empty($table) && (!isset($this->_table) || empty($this->_table))) {
$this->_table = $this->tablename($table);
}
if (empty($this->_table)) {
return false;
}
$this->_key = $key;
// So we know what the primary key is
$this->_datatypes = array();
// So we know the format of the table
$this->_lists = array();
// So we know the options for each list
$defaults = array();
// So we know the default values for each field
$map = !empty($this->_map) ? array_flip($this->_map) : array();
$Tables = $Settings->available() ? $Settings->get('data_model') : array();
if (isset($Tables[$this->_table])) {
$this->_datatypes = $Tables[$this->_table]->_datatypes;
$this->_lists = $Tables[$this->_table]->_lists;
$defaults = $Tables[$this->_table]->_defaults;
foreach ($this->_datatypes as $var => $type) {
$property = isset($map[$var]) ? $map[$var] : $var;
if (!isset($this->{$property})) {
$this->{$property} = isset($defaults[$var]) ? $defaults[$var] : '';
}
if ('date' == $type && ('0000-00-00 00:00:00' == $this->{$property} || empty($this->{$property}))) {
$this->{$property} = null;
}
}
return true;
}
if (!($r = sDB::query("SHOW COLUMNS FROM {$this->_table}", 'array'))) {
return false;
}
// Map out the table definition into our data structure
foreach ($r as $object) {
$var = $object->Field;
$this->_datatypes[$var] = sDB::datatype($object->Type);
$this->_defaults[$var] = $object->Default;
// Grab out options from list fields
if ('list' == sDB::datatype($object->Type)) {
$values = str_replace("','", ",", substr($object->Type, strpos($object->Type, "'") + 1, -2));
$this->_lists[$var] = explode(",", $values);
}
if (!empty($map) && !isset($map[$var])) {
continue;
}
// Remap properties if a property map is available
$property = isset($map[$var]) ? $map[$var] : $var;
if (!isset($this->{$property})) {
$this->{$property} = $this->_defaults[$var];
}
}
if ($Settings->available()) {
$Tables[$this->_table] = new StdClass();
$Tables[$this->_table]->_datatypes =& $this->_datatypes;
$Tables[$this->_table]->_lists =& $this->_lists;
$Tables[$this->_table]->_defaults =& $this->_defaults;
$Settings->save('data_model', $Tables);
}
return true;
}