本文整理匯總了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();
}