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


PHP JDatabase::insertObject方法代码示例

本文整理汇总了PHP中JDatabase::insertObject方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabase::insertObject方法的具体用法?PHP JDatabase::insertObject怎么用?PHP JDatabase::insertObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JDatabase的用法示例。


在下文中一共展示了JDatabase::insertObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * Can be overloaded/supplemented by the child class
  *
  * @access public
  * @param boolean If false, null object variables are not updated
  * @return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         $ret = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         //loading libraries
         $properties = $this->getProperties();
         //loading resources
         $user =& eFactory::getUser();
         //initializing object properties
         $this->_juser_id = $user->id;
         $this->{$k} = create_guid();
         if (array_key_exists('created_on', $properties)) {
             $this->created_on = date('Y-m-d H:i:s', time());
         }
         if ($ret = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key)) {
             $this->saveRelationship('juser');
         }
     }
     if (!$ret) {
         $this->setError(get_class($this) . '::store failed - ' . $this->_db->getErrorMsg());
         return false;
     } else {
         return true;
     }
 }
开发者ID:Jonathonbyrd,项目名称:Joomla-Listings,代码行数:36,代码来源:table.php

示例2: doCreate

 /**
  * Method to add an object to the database.
  *
  * @return  void
  *
  * @since   12.1
  * @throws  RuntimeException
  */
 protected function doCreate()
 {
     // Get the primary key.
     $primaryKey = $this->getTableKey('primary', 'primary');
     try {
         // Start a transaction.
         $this->db->transactionStart();
         // Store the data for each table.
         foreach ($this->tables as $alias => $table) {
             // Get the data for the table.
             $dump = $this->dumpTable($alias);
             // Store the data to the database.
             $this->db->insertObject($table, $dump, $primaryKey);
             // Update the primary id.
             if ($alias == 'primary') {
                 // Set the primary key value.
                 $this->{$primaryKey} = (int) $dump->{$primaryKey};
             }
         }
         // Commit the transaction.
         $this->db->transactionCommit();
     } catch (RuntimeException $error) {
         // Rollback the transaction.
         $this->db->transactionRollback();
         // Rethrow the error.
         throw $error;
     }
 }
开发者ID:prox91,项目名称:joomla-dev,代码行数:36,代码来源:object.php

示例3: store

 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * Can be overloaded/supplemented by the child class
  *
  * @access public
  * @param boolean If false, null object variables are not updated
  * @return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         $ret = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         $ret = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
     }
     if (!$ret) {
         $this->setError(get_class($this) . '::store failed - ' . $this->_db->getErrorMsg());
         return false;
     } else {
         return true;
     }
 }
开发者ID:hrishikesh-kumar,项目名称:NBSNIP,代码行数:24,代码来源:table.php

示例4: store

 /**
  * Method to store a row in the database from the JTable instance properties.
  * If a primary key value is set the row with that primary key value will be
  * updated with the instance property values.  If no primary key value is set
  * a new row will be inserted into the database with the properties from the
  * JTable instance.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  boolean  True on success.
  *
  * @link	http://docs.joomla.org/JTable/store
  * @since   11.1
  */
 public function store($updateNulls = false)
 {
     // Initialise variables.
     $k = $this->_tbl_key;
     if (!empty($this->asset_id)) {
         $currentAssetId = $this->asset_id;
     }
     // The asset id field is managed privately by this class.
     if ($this->_trackAssets) {
         unset($this->asset_id);
     }
     // If a primary key exists update the object, otherwise insert it.
     if ($this->{$k}) {
         $stored = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         $stored = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
     }
     // If the store failed return false.
     if (!$stored) {
         $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     // If the table is not set to track assets return true.
     if (!$this->_trackAssets) {
         return true;
     }
     if ($this->_locked) {
         $this->_unlock();
     }
     //
     // Asset Tracking
     //
     $parentId = $this->_getAssetParentId();
     $name = $this->_getAssetName();
     $title = $this->_getAssetTitle();
     $asset = JTable::getInstance('Asset', 'JTable', array('dbo' => $this->getDbo()));
     $asset->loadByName($name);
     // Re-inject the asset id.
     $this->asset_id = $asset->id;
     // Check for an error.
     if ($error = $asset->getError()) {
         $this->setError($error);
         return false;
     }
     // Specify how a new or moved node asset is inserted into the tree.
     if (empty($this->asset_id) || $asset->parent_id != $parentId) {
         $asset->setLocation($parentId, 'last-child');
     }
     // Prepare the asset to be stored.
     $asset->parent_id = $parentId;
     $asset->name = $name;
     $asset->title = $title;
     if ($this->_rules instanceof JAccessRules) {
         $asset->rules = (string) $this->_rules;
     }
     if (!$asset->check() || !$asset->store($updateNulls)) {
         $this->setError($asset->getError());
         return false;
     }
     // Create an asset_id or heal one that is corrupted.
     if (empty($this->asset_id) || $currentAssetId != $this->asset_id && !empty($this->asset_id)) {
         // Update the asset_id field in this table.
         $this->asset_id = (int) $asset->id;
         $query = $this->_db->getQuery(true);
         $query->update($this->_db->quoteName($this->_tbl));
         $query->set('asset_id = ' . (int) $this->asset_id);
         $query->where($this->_db->quoteName($k) . ' = ' . (int) $this->{$k});
         $this->_db->setQuery($query);
         if (!$this->_db->execute()) {
             $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED_UPDATE_ASSET_ID', $this->_db->getErrorMsg()));
             $this->setError($e);
             return false;
         }
     }
     return true;
 }
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:91,代码来源:table.php

示例5: insertObject

 /**
  * Insert an object into database
  *
  * @param  string  $table    This is expected to be a valid (and safe!) table name
  * @param  object  &$object  A reference to an object whose public properties match the table fields.
  * @param  string  $keyName  The name of the primary key. If provided the object property is updated.
  * @return boolean           TRUE if insert succeeded, FALSE when error
  *
  * @throws  \RuntimeException
  */
 public function insertObject($table, &$object, $keyName = null)
 {
     return $this->_db->insertObject($table, $object, $keyName);
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:14,代码来源:CmsDatabaseDriver.php

示例6: insertObject

 /**
  * Insert an object into a table
  *
  * @param AppTable $table The table object in which to insert the object
  * @param object $object The object to insert
  * @param string $key The name of the primary key of the table
  *
  * @return boolean If the operation was successful
  *
  * @throws RuntimeException
  *
  * @since 1.0.0
  */
 public function insertObject($table, $object, $key = null)
 {
     // insert object
     return $this->_database->insertObject($table, $object, $key);
 }
开发者ID:JBZoo,项目名称:Zoo-Changelog,代码行数:18,代码来源:database.php

示例7: insertObject

 /**
  * Insert an object into database
  *
  * @param  string   $table This is expected to be a valid (and safe!) table name
  * @param  object   $object
  * @param  string   $keyName
  * @param  boolean  $verbose
  * @return boolean  TRUE if insert succeeded, FALSE when error
  */
 function insertObject($table, &$object, $keyName = NULL, $verbose = false)
 {
     return $this->_db->insertObject($table, $object, $keyName, $verbose);
 }
开发者ID:rogatnev-nikita,项目名称:cloudinterpreter,代码行数:13,代码来源:cb.database.php

示例8: store

 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * Can be overloaded/supplemented by the child class
  *
  * @access public
  * @param boolean If false, null object variables are not updated
  * @return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = true)
 {
     $k = $this->_tbl_key;
     $wheres = array();
     // execute query and retrieve result
     $query = $this->_db->getQuery(true);
     $query->select(' 1 ');
     $query->from(' ' . $this->_db->quoteName($this->_tbl) . ' ');
     // check whether all fields are filled and build where statement
     for ($i = 0; $i < count($k); $i++) {
         if ($this->{$k}[$i] === null) {
             $this->setError(get_class($this) . '::store failed - primary key ' . $this->{$k} . ' is empty (null)');
             return false;
         } else {
             $wheres[] = ' ' . $this->_db->quoteName($k[$i]) . ' = ' . $this->_db->Quote($this->{$k}[$i]) . ' ';
         }
     }
     foreach ($wheres as $where) {
         $query->where($where);
     }
     $this->_db->setQuery($query);
     $result = $this->_db->loadResult();
     // if query has no result, record does not exists yet and is added here
     // if query has result, record exists and is updated here
     if (!$result) {
         $ret = $this->_db->insertObject($this->_tbl, $this);
     } else {
         $query->clear();
         $query->update($this->_db->quoteName($this->_tbl));
         $sets = array();
         foreach ($this->getProperties() as $name => $value) {
             if (is_array($value) or is_object($value) or $name[0] == '_') {
                 // internal or NA field
                 continue;
             }
             if (in_array($name, $k)) {
                 // PK not to be updated
                 continue;
             }
             if ($value === null) {
                 if ($updateNulls) {
                     $val = 'NULL';
                 } else {
                     continue;
                 }
             } else {
                 //$val = $this->_db->isQuoted( $name ) ? $this->_db->Quote( $value ) : (int) $value;
                 $val = $this->_db->Quote($value);
             }
             $sets[] = $this->_db->quoteName($name) . '=' . $val;
         }
         if (count($sets) > 0) {
             foreach ($sets as $set) {
                 $query->set($set);
             }
             foreach ($wheres as $where) {
                 $query->where($where);
             }
             $this->_db->setQuery($query);
             $ret = $this->_db->query();
         } else {
             $ret = true;
         }
     }
     if (!$ret) {
         $this->setError(get_class($this) . '::store failed - ' . $this->_db->getErrorMsg());
         return false;
     } else {
         return true;
     }
 }
开发者ID:Lothurm,项目名称:J3.x,代码行数:80,代码来源:JMFPKtable.php


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