mysqli聚合获取的值

时间:2013-11-04 15:44:28

标签: php reference mysqli fetch

我正在尝试编写封装mysqli逻辑的类(强烈使用堆栈溢出文章)并且我已经避免了这个问题: $ row 键引用了<已经获取的强>最近值,数组 $ rows 也是如此,我希望在其中汇总提取的值。如何将这些引用更改为值或(更有可能)执行此提取的正确方法是什么?

private function bind_array(&$row) {
    $md = $this->stmt->result_metadata();
    $params = array();
    while($field = $md->fetch_field()) {
        $params[] = &$row[$field->name];
    }

    if(!call_user_func_array(array($this->stmt, 'bind_result'), $params)) {
        throw new Exception($this->conn->error);
    }
}

public function select($query, $data_array, $letters) {

    $this->stmt = $this->conn->prepare($query);

    if(!$this->stmt) {
        throw new Exception($this->conn->error);
    }

    $return_array = array();

    foreach($data_array as $data) {
        array_unshift($data, implode('',$letters));

        $refs = array();

        foreach($data as $key => $value) {
            $refs[$key] = &$data[$key];
        }

        if(!call_user_func_array(array($this->stmt, 'bind_param'), $refs)) {
            throw new Exception($this->conn->error);
        }

        if($this->stmt->execute()) {

            $this->bind_array($row);

            while($this->stmt->fetch()) {

                $rows[] = $row;

            }

            echo "<pre>";
            var_dump($rows);
            exit;

        } else {
            throw new Exception($this->conn->error);
        }

        $return_array[] = $rows;

    }


    return $return_array;

}

0 个答案:

没有答案