本文整理汇总了PHP中DataAccess::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP DataAccess::getInstance方法的具体用法?PHP DataAccess::getInstance怎么用?PHP DataAccess::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataAccess
的用法示例。
在下文中一共展示了DataAccess::getInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveOrUpdate
/**
* Saves this entity if its a brand new instance that does not exist
* in the database; otherwise updates this entity in the database by
* flushing all its attributes directly to the database.
*/
public function saveOrUpdate()
{
try {
// if this entity has been destroyed then we cannot
// assert the validaty of this instance identity
// so we simply ignore any persistence operations.
if ($this->isDestroyed() == true) {
return;
}
// avoid getting fields array directly, in case a
// sub-class of this object overrides the default
// behavior for listing this objects fields.
$fields = $this->getAttributes();
if ($this->id) {
// since this is an update operation we
// update the modification timestamps.
if (array_key_exists('modified', $fields)) {
$this->modified = $this->getDate();
}
if (array_key_exists('modifiedid', $fields)) {
$this->modifiedid = time();
}
$sql = 'UPDATE ' . $this->class . ' SET ';
// attributes to update
foreach ($this->fields as $k => $v) {
$sql .= $this->assignUpdateSemantics($k, $v);
}
// constraint update to this instance identity.
$sql = rtrim($sql, ',') . ' WHERE id = ' . $this->id;
DataAccess::getInstance()->query($sql);
} else {
// since this is an update operation we
// update the modification timestamps.
if (array_key_exists('created', $fields) && $fields['created'] == '') {
$this->created = $this->getDate();
}
if (array_key_exists('createdid', $fields) && $fields['createdid'] == '') {
$this->createdid = time();
}
$sql = 'INSERT INTO ' . $this->class . ' (';
$values = '';
// values to insert
foreach ($this->fields as $k => $v) {
$sql .= $k . ',';
$values .= $this->assignInsertSemantics($v);
}
$sql = rtrim($sql, ',') . ') VALUES (' . rtrim($values, ',') . ')';
DataAccess::getInstance()->query($sql);
$this->id = DataAccess::getInstance()->lastInsertId();
}
} catch (Exception $exception) {
throw new Exception('Failed to complete save or update.');
}
}
示例2: __construct
public function __construct()
{
$this->dataAccess = DataAccess::getInstance();
}