1--TEST-- 2MySQL PDO->__construct(), PDO::MYSQL_ATTR_MAX_BUFFER_SIZE 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9if (MySQLPDOTest::isPDOMySQLnd()) 10 die("skip PDO::MYSQL_ATTR_MAX_BUFFER_SIZE not supported with mysqlnd"); 11?> 12--FILE-- 13<?php 14 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 15 16 function try_buffer_size($offset, $buffer_size) { 17 18 try { 19 20 $dsn = MySQLPDOTest::getDSN(); 21 $user = PDO_MYSQL_TEST_USER; 22 $pass = PDO_MYSQL_TEST_PASS; 23 24 /* unsigned overflow possible ? */ 25 $db = new PDO($dsn, $user, $pass, 26 array( 27 PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size, 28 /* buffer is only relevant with native PS */ 29 PDO::MYSQL_ATTR_DIRECT_QUERY => 0, 30 PDO::ATTR_EMULATE_PREPARES => 0, 31 )); 32 33 $db->exec('DROP TABLE IF EXISTS test'); 34 $db->exec(sprintf('CREATE TABLE test(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE)); 35 36 // 10 * (10 * 1024) = 10 * (10 * 1k) = 100k 37 $db->exec('INSERT INTO test(id, val) VALUES (1, REPEAT("01234567890", 10240))'); 38 39 $stmt = $db->prepare('SELECT id, val FROM test'); 40 $stmt->execute(); 41 42 $id = $val = NULL; 43 $stmt->bindColumn(1, $id); 44 $stmt->bindColumn(2, $val); 45 while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { 46 printf("[%03d] id = %d, val = %s... (length: %d)\n", 47 $offset, $id, substr($val, 0, 10), strlen($val)); 48 } 49 $db->exec('DROP TABLE IF EXISTS test'); 50 51 } catch (PDOException $e) { 52 printf("[%03d] %s, [%s] %s\n", 53 $offset, 54 $e->getMessage(), 55 (is_object($db)) ? $db->errorCode() : 'n/a', 56 (is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a'); 57 } 58 } 59 60 try_buffer_size(1, -1); 61 try_buffer_size(2, 1000); 62 try_buffer_size(4, 2000); 63 try { 64 try_buffer_size(3, NULL); 65 } catch (TypeError $e) { 66 echo $e->getMessage(), "\n"; 67 } 68 69 print "done!"; 70?> 71--CLEAN-- 72<?php 73require __DIR__ . '/mysql_pdo_test.inc'; 74$db = MySQLPDOTest::factory(); 75$db->exec('DROP TABLE IF EXISTS test'); 76?> 77--EXPECTF-- 78[001] id = 1, val = 0123456789... (length: %d) 79[002] id = 1, val = 0123456789... (length: 1000) 80[004] id = 1, val = 0123456789... (length: 2000) 81Attribute value must be of type int for selected attribute, null given 82done! 83