本文整理汇总了PHP中DBObject::DB方法的典型用法代码示例。如果您正苦于以下问题:PHP DBObject::DB方法的具体用法?PHP DBObject::DB怎么用?PHP DBObject::DB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBObject
的用法示例。
在下文中一共展示了DBObject::DB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDB
function getDB()
{
$this->db = new ImpPDO('sqlite:' . $this->TempFile);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
DBObject::$DB = $this->db;
ImpSQLBuilder::$DB = $this->db;
}
示例2: __construct
protected function __construct($ID = false)
{
assert(!empty($this->Properties));
assert(!isset($this->_classOverrides));
assert(!isset($this->RequiredFormFields));
assert(!isset($this->FormFields));
if (!empty($GLOBALS['DB'])) {
DBObject::$DB = $GLOBALS['DB'];
}
if (!empty($ID)) {
if (is_array($ID)) {
$this->setProperties($ID);
$this->_initialValues = $ID;
} else {
$ID = intval($ID);
if (empty($ID)) {
throw new InvalidArgumentException(get_class($this) . " constructor called with empty id {$ID}");
}
$Q = self::$DB->query($this->_generateSelect($this->DBTable, $this->Properties, "ID={$ID}"));
if (count($Q) < 1) {
throw new InvalidArgumentException(get_class($this) . " constructor called with ID {$ID} which is not in {$this->DBTable}");
} else {
assert(count($Q) == 1);
$this->ID = $ID;
$this->setProperties($Q[0]);
$this->_initialValues = $Q[0];
}
}
} else {
foreach ($this->Properties as $Name => $def) {
if (is_array($def)) {
assert(isset($def['type']));
$Type = $def['type'];
} else {
$Type = $def;
}
if (is_array($def) and array_key_exists('default', $def)) {
$this->{$Name} = $def['default'];
} else {
switch ($Type) {
case 'date':
case 'datetime':
case 'timestamp':
case 'integer':
$this->{$Name} = (int) 0;
break;
case 'double':
case 'currency':
$this->{$Name} = (double) 0;
case 'string':
case 'enum':
$this->{$Name} = '';
break;
case 'set':
$this->{$Name} = array();
break;
case 'collection':
break;
case 'object':
// TODO: this breaks __set(), presumably due to a recursive call: $this->$Name = null;
break;
case 'boolean':
$this->{$Name} = false;
break;
default:
throw new InvalidArgumentException('No default for property of type ' . $Type);
}
}
$this->_initialValues[$Name] = $this->{$Name};
}
}
}