php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38015 Can not set PDO_MYSQL_ATTR_MAX_BUFFER_SIZE
Submitted: 2006-07-05 13:28 UTC Modified: 2006-07-26 02:08 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: sunaoka+bugs dot php dot net at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.4 OS: Solaris
Private report: No CVE-ID: None
 [2006-07-05 13:28 UTC] sunaoka+bugs dot php dot net at gmail dot com
Description:
------------
I'm using pdo_mysql client library 4.1.20.
I need treat the data of 1MB or more.
But I can not set PDO_MYSQL_ATTR_MAX_BUFFER_SIZE.

Reproduce code:
---------------
$db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
var_dump($db->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024 * 1024 * 10));


Expected result:
----------------
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-05 17:32 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-07-06 08:41 UTC] sunaoka+bugs dot php dot net at gmail dot com
Thank you for your comment. I try using CVS snapshot, but I have another problem.
So, I can set PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, but it can not set the value.

Reproduce code:
---------------
$db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
var_dump($db->getAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE));
var_dump($db->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024 * 1024 * 10));
var_dump($db->getAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE));

Expected result:
----------------
int(1048576)
bool(true)
int(1048576)
 [2006-07-06 20:12 UTC] tony2001@php.net
Expected result:
----------------
int(1048576)
bool(true)
int(1048576)


Right, this is the expected and ACTUAL result.
I don't see any problems there.
 [2006-07-07 06:17 UTC] sunaoka+bugs dot php dot net at gmail dot com
Thank you for your comment. But, I do not understand why the result doesn't become `int(10485760)'.
I load `FileData' only 1MB.

I am using php5.2-200607060030.

Reproduce code:
---------------
try {
    $db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
    $db->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024 * 1024 * 10);

    $sql = 'SELECT LENGTH(FileData) FROM FileInfo WHERE Id = ?';
    $stmt = $db->prepare($sql);
    $stmt->execute(array(1));
    $result = $stmt->fetch();
    $stmt->closeCursor();

    echo 'LENGTH(FileData):     ', $result[0], "\n";

    $sql = 'SELECT FileData FROM FileInfo WHERE Id = ?';
    $stmt = $db->prepare($sql);
    $stmt->execute(array(1));

    $stmt->bindColumn('FileData', $lob, PDO::PARAM_LOB);
    $result = $stmt->fetch(PDO::FETCH_BOUND);

    file_put_contents('/tmp/foo', $lob);
    echo "filesize('/tmp/foo'): ", filesize('/tmp/foo'), "\n";

} catch (PDOException $exception) {
    echo $exception->getMessage(), "\n";
}

Expected result:
----------------
LENGTH(FileData):     6971569
filesize('/tmp/foo'): 1048576
 [2006-07-07 08:33 UTC] tony2001@php.net
>But, I do not understand why the result doesn't become `int(10485760)'.
Why should it become equal to the size of the buffer?
Buffer is used to read the data by pieces and you can change size of of these pieces.
This is why it's called "PDO_MYSQL_ATTR_MAX_BUFFER_SIZE" and not "PDO_MYSQL_ATTR_MAX_DATA_SIZE".
 [2006-07-07 12:08 UTC] sunaoka+bugs dot php dot net at gmail dot com
Thank you for your comment.

I understood why the result wasn't 'int(10485760)'. 
Then, why is there PDO_MYSQL_ATTR_MAX_BUFFER_SIZE?

After all, I cannot acquire data more than 1M byte. 
The error occurs though I tried according to the manual as follows. 

http://www.php.net/manual/en/ref.pdo.php#pdo.lobs

fpassthru($lob);

Warning:  fpassthru(): supplied argument is not a valid stream resource in ...

How can I load 1M data or more?
 [2006-07-13 06:14 UTC] sunaoka+bugs dot php dot net at gmail dot com
Thank you for your comment.

I understood why the result wasn't 'int(10485760)'. 
Then, why is there PDO_MYSQL_ATTR_MAX_BUFFER_SIZE?

After all, I cannot acquire data more than 1M byte. 
The error occurs though I tried according to the manual as follows. 

http://www.php.net/manual/en/ref.pdo.php#pdo.lobs

Reproduce code:
---------------
$db = $db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
$stmt = $db->prepare('SELECT FileData FROM FileInfo WHERE Id = ?');
$stmt->execute(array(1));
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);

header('Content-Type: image/jpeg');
fpassthru($lob);

Expected result:
----------------
Warning:  fpassthru(): supplied argument is not a valid stream resourcein ...

How can I load 1M data or more?
 [2006-07-26 01:23 UTC] m dot leuffen at gmx dot de
Hi there,

it seems that the buffer size can be set only during instanciation of the PDO.

Try this:

$pdo = new PDO ("connection_settings", "user", "pass", array (PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>1024*1024*50));

This should fix the problem.

(If not this may be a MySQL configuration issue. Check the max_allowed_packet_size setting in your mysql configuration - and make sure that my.cnf is on the right location)

Bye,
  Matthias
 [2006-07-26 02:08 UTC] sunaoka+bugs dot php dot net at gmail dot com
Thank you. It work as follows. 

$pdo = new PDO ("connection_settings", "user", "pass", array
(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>1024*1024*50));
 [2014-12-28 07:04 UTC] reach dot supermike at gmail dot com
On Ubuntu 14.04 LTS default with PHP 5.5.9, if you run the following code, you'll find it doesn't ship with PDO::MYSQL_ATTR_MAX_BUFFER_SIZE:

    $reflector = new ReflectionClass('PDO');
    var_dump($reflector->getConstants());

At least for the MySQL items of that result, I only get:

MYSQL_ATTR_USE_BUFFERED_QUERY
MYSQL_ATTR_LOCAL_INFILE
MYSQL_ATTR_INIT_COMMAND
MYSQL_ATTR_COMPRESS
MYSQL_ATTR_DIRECT_QUERY
MYSQL_ATTR_FOUND_ROWS
MYSQL_ATTR_IGNORE_SPACE
MYSQL_ATTR_SSL_KEY
MYSQL_ATTR_SSL_CERT
MYSQL_ATTR_SSL_CA
MYSQL_ATTR_SSL_CAPATH
MYSQL_ATTR_SSL_CIPHER
MYSQL_ATTR_SERVER_PUBLIC_KEY

In fact, looking for anything dealing with SIZE, I turn up nothing.

However, I found this interesting bit of information on the web:

"PDO::MYSQL_ATTR_MAX_BUFFER_SIZE (integer)
Maximum buffer size. Defaults to 1 MiB. This constant is not supported when compiled against mysqlnd."
SOURCE: http://docs.hhvm.com/manual/en/ref.pdo-mysql.php

Hard to believe I had to visit the Hack website to find that out. Sure enough, Ubuntu 14.04 ships with php5-mysqlnd instead of php5-mysql. So, I ran the following commands:

    apt-get remove php5-mysqlnd
    apt-get install php5-mysql
    php5enmod mysql
    service mysql stop
    service mysql start
    service apache2 stop
    service apache2 start

Now when I run the code, the MYSQL_ATTR_MAX_BUFFER_SIZE is there. Also, I can set it with setAttribute() and am not forced to set it in the connection as the 4th parameter.

For more information on mysqlnd versus mysql, please see this article:

https://wiki.php.net/doc/todo/mysqlnd_vs_libmysql
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC