예제 #1
0
파일: class_dm.php 프로젝트: holandacz/nb4
 /**
  * Creates and runs an UPDATE query to save the data from the object into the database
  *
  * @param	string	The system's table prefix
  * @param	string	The name of the database table to be affected (do not include TABLE_PREFIX in your argument)
  * @param	string	Specify the WHERE condition here. For example, 'userid > 10 AND posts < 50'
  * @param	boolean	Whether or not to actually run the query
  * @param	mixed	If this evaluates to true, the query will be delayed. If it is a string, that will be the name of the shutdown query.
  * @param boolean	Whether to return the number of affected rows
  *
  * @return	boolean	Returns true on success
  */
 function db_update($tableprefix, $table, $condition = '', $doquery = true, $delayed = false, $affected_rows = false)
 {
     if ($this->has_errors()) {
         return false;
     } else {
         if (is_array($this->{$table}) and !empty($this->{$table})) {
             $sql = $this->fetch_update_sql($tableprefix, $table, $condition);
             if ($doquery) {
                 if ($sql) {
                     //echo "<pre>$sql<hr /></pre>";
                     if ($delayed) {
                         if (is_string($delayed)) {
                             $this->dbobject->shutdown_query($sql, $delayed);
                         } else {
                             $this->dbobject->shutdown_query($sql);
                         }
                     } else {
                         $this->dbobject->query_write($sql);
                         if ($affected_rows) {
                             return $this->dbobject->affected_rows();
                         }
                     }
                 }
             } else {
                 echo "<pre>{$sql}<hr /></pre>";
             }
             return true;
         } else {
             return true;
         }
     }
 }