当前位置: 首页>>代码示例>>PHP>>正文


PHP DataAccess::getInstance方法代码示例

本文整理汇总了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.');
     }
 }
开发者ID:rjmunro,项目名称:php-commons,代码行数:59,代码来源:GenericActiveRecord.php

示例2: __construct

 public function __construct()
 {
     $this->dataAccess = DataAccess::getInstance();
 }
开发者ID:ntulip,项目名称:twitterpg,代码行数:4,代码来源:DataAccess.php


注:本文中的DataAccess::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。