/** * @covers SQLBuilder::delete */ public function testDelete() { $this->sql->delete('users'); $actual = $this->sql->__toString(); $excepted = "delete from users "; $this->assertEquals($actual, $excepted); }
public function delete($data) { $data = $this->process_data($data); $sql = new SQLBuilder($this->conn, $this->get_fully_qualified_table_name()); $sql->delete($data); $values = $sql->bind_values(); return $this->conn->query($this->last_sql = $sql->to_s(), $values); }
/** * Deletes records matching conditions in $options * * Does not instantiate models and therefore does not invoke callbacks * * Delete all using a hash: * * <code> * YourModel::delete_all(array('conditions' => array('name' => 'Tito'))); * </code> * * Delete all using an array: * * <code> * YourModel::delete_all(array('conditions' => array('name = ?', 'Tito'))); * </code> * * Delete all using a string: * * <code> * YourModel::delete_all(array('conditions' => 'name = "Tito")); * </code> * * An options array takes the following parameters: * * <ul> * <li><b>conditions:</b> Conditions using a string/hash/array</li> * <li><b>limit:</b> Limit number of records to delete (MySQL & Sqlite only)</li> * <li><b>order:</b> A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)</li> * </ul> * * @params array $options * return integer Number of rows affected */ public static function delete_all($options = array()) { $table = static::table(); $conn = static::connection(); $sql = new SQLBuilder($conn, $table->get_fully_qualified_table_name()); $conditions = is_array($options) ? $options['conditions'] : $options; if (is_array($conditions) && !is_hash($conditions)) { call_user_func_array(array($sql, 'delete'), $conditions); } else { $sql->delete($conditions); } if (isset($options['limit'])) { $sql->limit($options['limit']); } if (isset($options['order'])) { $sql->order($options['order']); } $values = $sql->bind_values(); $ret = $conn->query($table->last_sql = $sql->to_s(), $values); return $ret->rowCount(); }
public function delete($data) { $data = $this->processData($data); $sql = new SQLBuilder($this->conn, $this->getFullyQualifiedTableName()); $sql->delete($data); $values = $sql->bindValues(); return $this->conn->query($this->lastSql = $sql->toS(), $values); }
$token = ClientLogin::getAuthToken('username', 'password'); $ftclient = new FTClientLogin($token); //show all tables echo $ftclient->query(SQLBuilder::showTables()); echo "<br />"; //describe a table echo $ftclient->query(SQLBuilder::describeTable(358077)); echo "<br />"; //select * from table echo $ftclient->query(SQLBuilder::select(358077)); echo "<br />"; //select * from table where test=1 echo $ftclient->query(SQLBuilder::select(358077, null, "'test'=1")); echo "<br />"; //select test from table where test = 1 echo $ftclient->query(SQLBuilder::select(358077, array('test'), "'test'=1")); echo "<br />"; //select rowid from table echo $ftclient->query(SQLBuilder::select(358077, array('rowid'))); echo "<br />"; //delete row 401 echo $ftclient->query(SQLBuilder::delete(358077, '401')); echo "<br />"; //drop table echo $ftclient->query(SQLBuilder::dropTable(358731)); echo "<br />"; //update table test=1 where rowid=1 echo $ftclient->query(SQLBuilder::update(358077, array('test' => 12), 1)); echo "<br />"; //insert into table (test, test2, 'another test') values (12, 3.3333, 'bob') echo $ftclient->query(SQLBuilder::insert(358077, array('test' => 12, 'test2' => 3.33333, 'another test' => 'bob')));