我想提取取决于多个条件从MySQL数据库的数据,但我的行为函数中使用数组中的面向对象的编程让我来提取仅基于1个条件数据。难度在PHP
请帮我修改操作函数,这样我可以使用多个阵列来提取数据。
public function query($sql, $params = array()) {
$this->error = false;
if ($this->query = $this->pdo->prepare($sql)) {
$x = 1;
if (count($params)) {
foreach ($params as $param) {
$this->query->bindValue($x, $param);
$x++;
}
}
if ($this->query->execute()) {
$this->results = $this->query->fetchAll(PDO::FETCH_OBJ);
$this->count = $this->query->rowCount();
} else {
$this->error = true;
}
}
return $this;
}
public function action($action, $table, $where = array()) {
if (count($where === 3)) {
$operators = array('=', '>', '<', '>=', '<=');
$field = $where[0];
$operator = $where[1];
$value = $where[2];
if (in_array($operator, $operators)) {
$sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
if (!$this->query($sql, array($value))->error()) {
return $this;
}
}
}
return false;
}
public function get($table, $where) {
return $this->action('SELECT *', $table, $where);
}
这是对最坏的可能设计一个数据库抽象层,你可以拿出。 'action'?祝你好运,当你尝试使用'更新'。 – 2014-11-24 17:31:10