【问题标题】:I'm trying to query my mysql db with mysqli, however I'm getting memory error我正在尝试使用 mysqli 查询我的 mysql 数据库,但是出现内存错误
【发布时间】:2014-08-24 21:00:23
【问题描述】:

这是我得到的错误: Allowed memory size of 1258291200 bytes exhausted (tried to allocate 4294967296 bytes)

在这条线上:call_user_func_array(array($query, 'bind_result'), $params);

有趣的是,我已经使用这个确切的脚本数十次了,没有任何问题。所以我认为这可能是我的服务器/数据库设置中的一些东西,但想不出任何东西。

这是完整的功能:

public function q($query) {
        if ($query = $this->_mysqli->prepare($query)) {
            if (func_num_args() > 1) {
                $x = func_get_args();
                $args = array_merge(array(func_get_arg(1)),
                    array_slice($x, 2));
                $args_ref = array();
                foreach($args as $k => &$arg) {
                    $args_ref[$k] = &$arg; 
                }
                call_user_func_array(array($query, 'bind_param'), $args_ref);
            }
            $query->execute();

            if ($query->errno) {
              if ($this->_debug) {
                echo mysqli_error($this->_mysqli);
                debug_print_backtrace();
              }
              return false;
            }

            if ($query->affected_rows > -1) {
                return $query->affected_rows;
            }
            $params = array(); 
            $meta = $query->result_metadata();
            while ($field = $meta->fetch_field()) {
                $params[] = &$row[$field->name];
            }

            call_user_func_array(array($query, 'bind_result'), $params);

            $result = array();
            while ($query->fetch()) {
                $r = array();
                foreach ($row as $key => $val) {
                    $r[$key] = $val;
                }
                $result[] = $r;
            }
            $query->close();

            foreach($result as $key=>$resultField){
                $result[$key] = (object) $resultField;
            }

            return $result;
        } else {
            if ($this->_debug) {
                echo $this->_mysqli->error;
                debug_print_backtrace();
            }
            return false;
        }
    }

请不要告诉我增加内存限制。我正在寻找解决问题的方法,而不是症状。

【问题讨论】:

    标签: php mysql mysqli


    【解决方案1】:

    原来我不必要地使用了longtext 并耗尽了我所有的内存。切换到mediumtext 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 2013-05-09
      • 2021-01-26
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      相关资源
      最近更新 更多