Пример #1
0
 /**
  * Performs an INSERT or an UPDATE; if the $value parameter is not falsy, 
  * an UPDATE is performed with the given column name and value, otherwise 
  * an insert. It is recommended that this is used for tables with a primary 
  * key, and use the primary key as the column to look at. Also, this would 
  * keep the return value consistent.
  * 
  * @param mixed $tableName		The table name to INSERT or UPDATE to
  * @param mixed $data		    The data to change
  * @param mixed $columnName		The column to search by. It should be
  *					            a primary key.
  * @param mixed $value		    (Optional) The value to look for in
  *					            case you want
  *					            to UPDATE. Keep this at null, 0,
  *					            or anything else falsy for INSERT.
  *
  * @return int			        If the $value is not falsy, it returns
  *					            $value after UPDATING. Otherwise the
  *					            mysql_insert_id() of the newly
  *					            INSERTED row.
  */
 public function save($tableName, $data, $columnName, $value = null)
 {
     if ($value) {
         $where = AMysql_Abstract::escapeIdentifier($columnName) . ' = ?';
         $this->update($tableName, $data, $where, array($value));
         return $value;
     } else {
         $id = $this->insert($tableName, $data);
         return $id;
     }
 }
Пример #2
0
 public function testTranspose()
 {
     $input = array(3 => array('col1' => 'bla', 'col2' => 'yo'), 9 => array('col1' => 'ney', 'col2' => 'lol'));
     $expected = array('col1' => array(3 => 'bla', 9 => 'ney'), 'col2' => array(3 => 'yo', 9 => 'lol'));
     $result = AMysql_Abstract::transpose($input);
     $this->assertEquals($expected, $result);
 }
Пример #3
0
 public function escapeColumn($column)
 {
     if ($this->amysql instanceof AMysql_Abstract) {
         return $this->amysql->escapeColumn($column);
     }
     return AMysql_Abstract::escapeIdentifier($column);
 }