php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36345 Problem loading BLOB over 1MB
Submitted: 2006-02-09 20:07 UTC Modified: 2006-02-14 15:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: milanm at datax dot biz Assigned: george (profile)
Status: Closed Package: PDO related
PHP Version: 5.1.2 OS: Linux
Private report: No CVE-ID: None
 [2006-02-09 20:07 UTC] milanm at datax dot biz
Description:
------------
I got a table and a stored 1.5 MB image in it. But when i try to load it into variable using PDO it has only 1MB. I'm using pdo_mysql client library 5.0.18.

Reproduce code:
---------------
<?php

  error_reporting(E_ALL);

  $dsn        = 'mysql:host=10.0.0.102;port=3306;dbname=test;';
  $user       = 'user';
  $password   = 'pass';

  $mysql_pdo  = new PDO($dsn, $user, $password);
  $blob_id    = 1;

  $stmt = $mysql_pdo->prepare('SELECT data FROM test WHERE id=:id');
  $stmt->bindParam(':id', $blob_id, PDO::PARAM_INT);

  $mysql_pdo->beginTransaction();
  $stmt->execute();
  $mysql_pdo->commit();

  $stmt->bindColumn(1, $blob_fp, PDO::PARAM_LOB);

  $stmt->fetchAll(PDO::FETCH_BOUND);

  header('Content-Type: image/jpeg');
  print $blob_fp;

?>
Table looks like this:

CREATE TABLE test (
  id      INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  name    VARCHAR(10) NOT NULL,
  data    LONGBLOB NOT NULL,
  PRIMARY KEY id (id),
  UNIQUE KEY name (name)
) type=InnoDB;



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-09 22:48 UTC] milanm at datax dot biz
When I run code bellow everithing is OK and data are 1.5 MB big. I've also tried to downgrade mysql to 4.1 and recompile php but with no results. Same problem persits with PDO using client library 4.1.14.
<?php

  $c  = mysql_connect('10.0.0.102', 'user', 'pass');
  mysql_select_db('test', $c);

  $res = mysql_query('SELECT data FROM test WHERE id=1', $c);

  $data = mysql_fetch_object($res);

  var_dump($data);

?>
 [2006-02-10 11:16 UTC] milanm at datax dot biz
I found something strange in ext/pdo_mysql/mysql_statement.c
There is constant defined called PDO_MYSQL_MAX_BUFFER like this:
#define PDO_MYSQL_MAX_BUFFER 1024*1024
I've changed this to:
#define PDO_MYSQL_MAX_BUFFER 1024*1024*10
and recompiled PHP.
Now PDO loads whole 1.5MB from DB.
Hope that helps.
 [2006-02-10 15:17 UTC] tony2001@php.net
Assigned to the maintainer.
 [2006-02-14 15:26 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

For large buffers > 1 meg, there was an option added PDO_MYSQL_ATTR_MAX_BUFFER_SIZE that allows you to indicate the desired maximum buffer size.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 22:01:27 2024 UTC