|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
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)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'): 1048576Hi 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, MatthiasThank you. It work as follows. $pdo = new PDO ("connection_settings", "user", "pass", array (PDO::MYSQL_ATTR_MAX_BUFFER_SIZE=>1024*1024*50));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