|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51386 mysql tries to allocate 4294967296 bytes when fetching longtext via mysqli
Submitted: 2010-03-25 08:19 UTC Modified: 2010-04-07 20:45 UTC
Avg. Score:4.4 ± 0.8
Reproduced:9 of 10 (90.0%)
Same Version:3 (33.3%)
Same OS:1 (11.1%)
From: rellig at minad dot de Assigned: mysql
Status: Wont fix Package: MySQLi related
PHP Version: 5.2.13 OS: gentoo
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-03-25 08:19 UTC] rellig at minad dot de
I wanted to fetch some lines in a php script via mysqli-prepared-statement and got this
Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes)
I was confused because php reportet that this error occured at bind_result.
After some time I figured out that it works when I turn one field with LONGTEXT type to
VARCHAR, for example.

here is a link to my php-script:

you can look at too.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-25 10:20 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2010-04-07 20:37 UTC]
From the link:

function news_read($limit = 0) {
	if($limit == 0)
		$qry = "SELECT * FROM news ORDER BY n_id DESC";
		$qry = "SELECT * FROM news ORDER BY n_id DESC LIMIT $limit";
	echo $qry;
	$stmt = $this->db->prepare($qry);
	while($stmt->fetch()) {
		$n_ids[] = $n_id;
		$n_titles[] = $n_title;
		$n_notes[] = $n_note;
		$n_times[] = $n_time;
		$n_authors[] = $n_author;
	return array(ids => $n_ids, titles => $n_titles, notes => $n_notes, times => $n_times, authors => $n_authors);
 [2010-04-07 20:45 UTC]
-Status: Assigned +Status: Wont fix
 [2010-04-07 20:45 UTC]
This is a known limitation of ext/mysqli when using libmysql (always in 5.2 and previous) and when libmysql is enabled with 5.3 . The reason is that the server sends not too specific metadata about the column. This longtext has a max length of 4G and ext/mysqli tries to bind with the max length, to be sure no data loss occurs (data doesn't fit in the bind buffer on C level). However, that means 4G for a longtext/longblob column. ext/mysqli has been changed to have a way to work around that. You need to call mysqli_stmt_store_result() which will store the data locally, which means, of course a higher memory usage for PHP. However, because you use libmysql this won't hit the PHP's memory limit, for sure. During store_result the max_length of every column will be calculated and then when bind_result is executed only a buffer with size of max_length will be allocated, which will be definitely lower than 4G.
In short,

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 15:01:30 2015 UTC