1--TEST-- 2MySQL Prepared Statements and BLOBs 3--SKIPIF-- 4<?php 5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); 6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 7MySQLPDOTest::skip(); 8?> 9--FILE-- 10<?php 11 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 12 $db = MySQLPDOTest::factory(); 13 14 $blobs = array( 15 'TINYBLOB' => 255, 16 'TINYTEXT' => 255, 17 'BLOB' => 32767, 18 'TEXT' => 32767, 19 'MEDIUMBLOB' => 100000, 20 'MEDIUMTEXT' => 100000, 21 'LONGBLOB' => 100000, 22 'LONGTEXT' => 100000, 23 ); 24 25 function test_blob($db, $offset, $sql_type, $test_len) { 26 27 $db->exec('DROP TABLE IF EXISTS test'); 28 $db->exec(sprintf('CREATE TABLE test(id INT, label %s) ENGINE=%s', $sql_type, PDO_MYSQL_TEST_ENGINE)); 29 30 $value = str_repeat('a', $test_len); 31 $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (?, ?)'); 32 $stmt->bindValue(1, 1); 33 $stmt->bindValue(2, $value); 34 if (!$stmt->execute()) { 35 printf("[%03d + 1] %d %s\n", 36 $offset, $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 37 return false; 38 } 39 40 $stmt = $db->query('SELECT id, label FROM test'); 41 $id = $label = NULL; 42 $stmt->bindColumn(1, $id, PDO::PARAM_INT); 43 $stmt->bindColumn(2, $label, PDO::PARAM_LOB); 44 45 if (!$stmt->fetch(PDO::FETCH_BOUND)) { 46 printf("[%03d + 2] %d %s\n", 47 $offset, $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 48 return false; 49 } 50 51 if ($label !== $value) { 52 printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d characters). Check manually\n", 53 $offset, strlen($label), strlen($value)); 54 return false; 55 } 56 57 if (1 != $id) { 58 printf("[%03d + 3] Returned id column value seems wrong, expecting 1 got %s.\n", 59 $offset, var_export($id, true)); 60 return false; 61 } 62 63 $stmt = $db->query('SELECT id, label FROM test'); 64 $ret = $stmt->fetch(PDO::FETCH_ASSOC); 65 66 if ($ret['label'] !== $value) { 67 printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d characters). Check manually\n", 68 $offset, strlen($ret['label']), strlen($value)); 69 return false; 70 } 71 72 if (1 != $ret['id']) { 73 printf("[%03d + 3] Returned id column value seems wrong, expecting 1 got %s.\n", 74 $offset, var_export($ret['id'], true)); 75 return false; 76 } 77 78 return true; 79 } 80 81 $offset = 0; 82 foreach ($blobs as $sql_type => $test_len) { 83 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 84 test_blob($db, ++$offset, $sql_type, $test_len); 85 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 86 test_blob($db, ++$offset, $sql_type, $test_len); 87 } 88 89 print "done!"; 90?> 91--CLEAN-- 92<?php 93require dirname(__FILE__) . '/mysql_pdo_test.inc'; 94$db = MySQLPDOTest::factory(); 95$db->exec('DROP TABLE IF EXISTS test'); 96?> 97--EXPECTF-- 98done! 99