0

我正在尝试编写封装 mysqli 逻辑的类(强烈使用堆栈溢出文章)并且我遇到了这个问题:$row keys reference to the recent values that have been fetched,数组$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;

}
4

0 回答 0