Exemple #1
0
 public function replace($option = null)
 {
     $this->id = null;
     if (empty($this->table)) {
         return false;
     }
     $attributes = array_merge($this->_qualifiers, $this->_attributes);
     if (empty($attributes)) {
         return false;
     }
     $pairs = $attributes;
     foreach ($pairs as $key => $value) {
         if (is_null($value)) {
             $pairs[$key] = 'NULL';
         }
     }
     $attributeFields = $this->_capsulateFields(array_keys($attributes));
     if (in_array(POD::dbms(), array('MySQL', 'MySQLi', 'SQLite3'))) {
         // Those supports 'REPLACE'
         $this->_query = 'REPLACE INTO ' . $this->table . ' (' . implode(',', $attributeFields) . ') VALUES(' . implode(',', $pairs) . ')';
         if ($option == 'count') {
             return POD::queryCount($this->_query);
         }
         if (POD::query($this->_query)) {
             $this->id = POD::insertId();
             return true;
         }
         return false;
     } else {
         $this->_query = 'SELECT * FROM ' . $this->table . $this->_makeWhereClause() . ' LIMIT 1';
         if (POD::queryExistence($this->_query)) {
             return $this->update($option);
         } else {
             return $this->insert($option);
         }
     }
 }
Exemple #2
0
 public function replace($option = null)
 {
     $this->id = null;
     if (empty($this->table)) {
         return false;
     }
     $this->_called = true;
     // Use first qualifiers when multiple conditions exist.
     $qualifiers = array();
     if (!empty($this->_qualifiers)) {
         foreach ($this->_qualifiers as $key => $index) {
             $qualifiers[$key] = reset($index);
         }
     }
     $attributes = array_merge($qualifiers, $this->_attributes);
     if (empty($attributes)) {
         return false;
     }
     $pairs = $attributes;
     foreach ($pairs as $key => $value) {
         if (is_null($value)) {
             $pairs[$key] = 'NULL';
         }
     }
     $attributeFields = $this->_capsulateFields(array_keys($attributes));
     if (in_array(POD::dbms(), array('MySQLnd', 'MySQLi', 'SQLite3'))) {
         // Those supports 'REPLACE'
         $this->_query = 'REPLACE INTO ' . $this->_getTableName() . ' (' . implode(',', $attributeFields) . ') VALUES(' . implode(',', $pairs) . ')';
         if ($option == 'count') {
             return POD::queryCount($this->_query);
         }
         $result = POD::query($this->_query);
         if ($result) {
             $this->id = POD::insertId();
             $this->_manage_pool_stack();
             return true;
         }
         return false;
     } else {
         $this->_query = 'SELECT * FROM ' . $this->_getTableName() . $this->_makeWhereClause() . ' LIMIT 1';
         $result = POD::queryExistence($this->_query);
         if ($result) {
             return $this->update($option);
         } else {
             return $this->insert($option);
         }
     }
 }