简体   繁体   中英

I'm trying to query my mysql db with mysqli, however I'm getting memory error

This is the error I'm getting: Allowed memory size of 1258291200 bytes exhausted (tried to allocate 4294967296 bytes)

on this line: call_user_func_array(array($query, 'bind_result'), $params);

Funnily enough, I've used this exact script dozens of time without issue. So I think it might be something in my server/db set up but can't think of anything.

Here's the full function:

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;
        }
    }

Please do not tell me to increase the memory limit. I'm looking for a fix to the problem, not the symptom.

Turns out I was using longtext unnecessarily and using up all my memory. Switching to mediumtext solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM