$db->select("users")->where(array("username", "=", "username"));
$db->update("users", array("username" => "username", "password" => "12345"))->where(array("id", "=", "14"));
好吧,我想通過將where()方法鏈接到select,update和delete來編寫類似上面的語句。 我的問題是;如何確定在where之前是否使用了select,update或delete,所以我可以將正確的值綁定到正確的語句上。PHP中的鏈接方法
我想是這樣的:
public function where() {
if($this->select()) {
// so if $db->select("users")->where(array("username", "=", "username"));
// save the where data in the select variable.
}
elseif($this->update()) {
// so if $db->update("users", array("username" => "username", "password" => "12345"))->where(array("id", "=", "14"));
// save the where data in the update variable.
}
elseif($this->delete()) {
// so if $db->delete("users")->where(array("username", "=", "username"));
// save the where data in the delete variable.
}
}
但上面的代碼當然是無效的,而且我不使用任何框架。
public function select($table, $what = null) {
$what == null ? $what = "*" : $what;
$this->_select = "SELECT {$what} FROM {$table}";
return $this;
}
我d建議在'select','update'和'delete'方法中設置標誌。 – hjpotter92 2014-11-02 19:34:52