Exemple #1
0
 /**
  * Execute the current update builded query
  * 
  * @param string $config    [optional] Config to use from the current config file. Default is "db1"
  * @return integer          Return the number of affected rows
  */
 public function execute($config = 'db1')
 {
     $sql = 'UPDATE ' . DB::quoteTable($this->_table, $config) . ' SET ';
     $i = 0;
     $fields = array();
     foreach ($this->_values as $k => $v) {
         $i++;
         $fields[] = DB::quoteIdentifier($k) . '=:val' . $i;
         $this->_vars['val' . $i] = $v;
     }
     $sql .= join(',', $fields) . ' ';
     $sql .= $this->_buildWhere();
     $q = Db::query($sql, $config)->execute($this->_vars);
     return is_object($q) ? $q->count() : 0;
 }
Exemple #2
0
 /**
  * Execute the insert into the given table
  * 
  * @return string      Return the inserted ID
  */
 public function execute()
 {
     $sql = 'INSERT INTO ' . DB::quoteTable($this->_table, $this->_config) . ' ';
     $cols = array();
     $vals = array();
     foreach ($this->_values as $k => $v) {
         is_string($k) ? $cols[] = $k : ($k = 'var_' . $k);
         $vals[':' . $k] = $v;
     }
     if (!empty($cols)) {
         $sql .= '(' . join(',', array_map(array('DB', 'quoteIdentifier'), $cols)) . ') ';
     }
     $sql .= 'VALUES (' . join(', ', array_keys($vals)) . ')';
     $q = Db::query($sql, $this->_config)->execute($vals);
     if (!is_object($q)) {
         return false;
     }
     $q->reset();
     return Db::getInstance($this->_config)->getLastId();
 }