1--TEST-- 2MySQL PDOStatement->bindParam() - SQL column types 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10?> 11--FILE-- 12<?php 13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 14 $db = MySQLPDOTest::factory(); 15 MySQLPDOTest::createTestTable($db); 16 17 function pdo_mysql_stmt_bindparam_types_do($db, $offset, $native, $sql_type, $value) { 18 19 if ($native) 20 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0); 21 else 22 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); 23 24 $db->exec('DROP TABLE IF EXISTS test'); 25 $sql = sprintf('CREATE TABLE test(id INT, label %s) ENGINE=%s', $sql_type, MySQLPDOTest::getTableEngine()); 26 if ((!$stmt = @$db->prepare($sql)) || (!@$stmt->execute())) 27 // Server might not support column type - skip it 28 return true; 29 30 $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (1, ?)'); 31 if (!$stmt->bindParam(1, $value)) { 32 printf("[%03d/%s + 1] %s\n", $offset, ($native) ? 'native' : 'emulated', 33 var_export($stmt->errorInfo(), true)); 34 return false; 35 } 36 if (!$stmt->execute()) { 37 printf("[%03d/%s + 2] %s\n", $offset, ($native) ? 'native' : 'emulated', 38 var_export($stmt->errorInfo(), true)); 39 return false; 40 } 41 42 $stmt = $db->query('SELECT id, label FROM test'); 43 $id = $label = null; 44 if (!$stmt->bindColumn(1, $id)) { 45 printf("[%03d/%s + 3] %s\n", $offset, ($native) ? 'native' : 'emulated', 46 var_export($stmt->errorInfo(), true)); 47 return false; 48 } 49 if (!$stmt->bindColumn(2, $label)) { 50 printf("[%03d/%s + 4] %s\n", $offset, ($native) ? 'native' : 'emulated', 51 var_export($stmt->errorInfo(), true)); 52 return false; 53 } 54 55 if (!$stmt->fetch(PDO::FETCH_BOUND)) { 56 printf("[%03d/%s + 5] %s\n", $offset, ($native) ? 'native' : 'emulated', 57 var_export($stmt->errorInfo(), true)); 58 return false; 59 } 60 $stmt->closeCursor(); 61 62 if ($label != $value) { 63 printf("[%03d/%s + 6] Got %s expecting %s - please check manually\n", 64 $offset, ($native) ? 'native' : 'emulated', 65 var_export($label, true), var_export($value, true)); 66 // fall through 67 } 68 69 $stmt->execute(); 70 $row = $stmt->fetch(PDO::FETCH_ASSOC); 71 if (empty($row)) { 72 printf("[%03d/%s + 7] %s\n", $offset, ($native) ? 'native' : 'emulated', 73 var_export($stmt->errorInfo(), true)); 74 return false; 75 } 76 77 if ($row['label'] != $value) { 78 printf("[%03d/%s + 8] Got %s expecting %s - please check manually\n", 79 $offset, ($native) ? 'native' : 'emulated', 80 var_export($row['label'], true), var_export($value, true)); 81 return false; 82 } 83 84 if ($row['label'] != $label) { 85 printf("[%03d/%s + 9] Got %s from FETCH_ASSOC and %s from FETCH_BOUND- please check manually\n", 86 $offset, ($native) ? 'native' : 'emulated', 87 var_export($row['label'], true), var_export($value, true)); 88 return false; 89 } 90 91 $db->exec('DROP TABLE IF EXISTS test'); 92 return true; 93 } 94 95 function pdo_mysql_stmt_bindparam_types($db, $offset, $sql_type, $value) { 96 97 pdo_mysql_stmt_bindparam_types_do($db, $offset, true, $sql_type, $value); 98 pdo_mysql_stmt_bindparam_types_do($db, $offset, false, $sql_type, $value); 99 100 } 101 102 try { 103 104 // pdo_mysql_stmt_bindparam_types($db, 2, 'BIT(8)', 1); 105 pdo_mysql_stmt_bindparam_types($db, 3, 'TINYINT', -127); 106 pdo_mysql_stmt_bindparam_types($db, 4, 'TINYINT UNSIGNED', 255); 107 pdo_mysql_stmt_bindparam_types($db, 5, 'BOOLEAN', 1); 108 pdo_mysql_stmt_bindparam_types($db, 6, 'SMALLINT', -32768); 109 pdo_mysql_stmt_bindparam_types($db, 7, 'SMALLINT UNSIGNED', 65535); 110 pdo_mysql_stmt_bindparam_types($db, 8, 'MEDIUMINT', -8388608); 111 pdo_mysql_stmt_bindparam_types($db, 9, 'MEDIUMINT UNSIGNED', 16777215); 112 pdo_mysql_stmt_bindparam_types($db, 10, 'INT', -2147483648); 113 pdo_mysql_stmt_bindparam_types($db, 11, 'INT UNSIGNED', 4294967295); 114 pdo_mysql_stmt_bindparam_types($db, 12, 'BIGINT', -1000); 115 pdo_mysql_stmt_bindparam_types($db, 13, 'BIGINT UNSIGNED', 1000); 116 pdo_mysql_stmt_bindparam_types($db, 14, 'REAL', -1000); 117 pdo_mysql_stmt_bindparam_types($db, 15, 'REAL UNSIGNED', 1000); 118 pdo_mysql_stmt_bindparam_types($db, 16, 'REAL ZEROFILL', '0000000000000000000000'); 119 pdo_mysql_stmt_bindparam_types($db, 17, 'REAL UNSIGNED ZEROFILL', '0000000000000000000010'); 120 pdo_mysql_stmt_bindparam_types($db, 18, 'DOUBLE', -1000); 121 pdo_mysql_stmt_bindparam_types($db, 19, 'DOUBLE UNSIGNED', 1000); 122 pdo_mysql_stmt_bindparam_types($db, 20, 'DOUBLE ZEROFILL', '000000000000'); 123 pdo_mysql_stmt_bindparam_types($db, 21, 'DOUBLE ZEROFILL UNSIGNED', '000000001000'); 124 pdo_mysql_stmt_bindparam_types($db, 22, 'FLOAT', -1000); 125 pdo_mysql_stmt_bindparam_types($db, 23, 'FLOAT UNSIGNED', 1000); 126 pdo_mysql_stmt_bindparam_types($db, 24, 'FLOAT ZEROFILL', '000000000000'); 127 pdo_mysql_stmt_bindparam_types($db, 25, 'FLOAT ZEROFILL UNSIGNED', '000000001000'); 128 pdo_mysql_stmt_bindparam_types($db, 26, 'DECIMAL', -1000); 129 pdo_mysql_stmt_bindparam_types($db, 27, 'DECIMAL UNSIGNED', 1000); 130 pdo_mysql_stmt_bindparam_types($db, 28, 'DECIMAL ZEROFILL', '000000000000'); 131 pdo_mysql_stmt_bindparam_types($db, 29, 'DECIMAL ZEROFILL UNSIGNED', '000000001000'); 132 pdo_mysql_stmt_bindparam_types($db, 30, 'NUMERIC', -1000); 133 pdo_mysql_stmt_bindparam_types($db, 31, 'NUMERIC UNSIGNED', 1000); 134 pdo_mysql_stmt_bindparam_types($db, 32, 'NUMERIC ZEROFILL', '000000000000'); 135 pdo_mysql_stmt_bindparam_types($db, 33, 'NUMERIC ZEROFILL UNSIGNED', '000000001000'); 136 pdo_mysql_stmt_bindparam_types($db, 34, 'DATE', '2008-04-23'); 137 pdo_mysql_stmt_bindparam_types($db, 35, 'TIME', '16:43:12'); 138 pdo_mysql_stmt_bindparam_types($db, 36, 'TIMESTAMP', '2008-04-23 16:44:53'); 139 pdo_mysql_stmt_bindparam_types($db, 37, 'DATETIME', '2008-04-23 16:44:53'); 140 pdo_mysql_stmt_bindparam_types($db, 38, 'YEAR', '2008'); 141 pdo_mysql_stmt_bindparam_types($db, 39, 'CHAR(1)', 'a'); 142 pdo_mysql_stmt_bindparam_types($db, 40, 'CHAR(255)', 'abc'); 143 pdo_mysql_stmt_bindparam_types($db, 41, 'VARCHAR(255)', str_repeat('a', 255)); 144 pdo_mysql_stmt_bindparam_types($db, 42, 'BINARY(255)', str_repeat('a', 255)); 145 pdo_mysql_stmt_bindparam_types($db, 43, 'VARBINARY(255)', str_repeat('a', 255)); 146 pdo_mysql_stmt_bindparam_types($db, 44, 'TINYBLOB', str_repeat('a', 255)); 147 pdo_mysql_stmt_bindparam_types($db, 45, 'BLOB', str_repeat('b', 300)); 148 pdo_mysql_stmt_bindparam_types($db, 46, 'MEDIUMBLOB', str_repeat('b', 300)); 149 pdo_mysql_stmt_bindparam_types($db, 47, 'LONGBLOB', str_repeat('b', 300)); 150 pdo_mysql_stmt_bindparam_types($db, 48, 'TINYTEXT', str_repeat('c', 255)); 151 pdo_mysql_stmt_bindparam_types($db, 49, 'TINYTEXT BINARY', str_repeat('c', 255)); 152 pdo_mysql_stmt_bindparam_types($db, 50, 'TEXT', str_repeat('d', 300)); 153 pdo_mysql_stmt_bindparam_types($db, 51, 'TEXT BINARY', str_repeat('d', 300)); 154 pdo_mysql_stmt_bindparam_types($db, 52, 'MEDIUMTEXT', str_repeat('d', 300)); 155 pdo_mysql_stmt_bindparam_types($db, 53, 'MEDIUMTEXT BINARY', str_repeat('d', 300)); 156 pdo_mysql_stmt_bindparam_types($db, 54, 'LONGTEXT', str_repeat('d', 300)); 157 pdo_mysql_stmt_bindparam_types($db, 55, 'LONGTEXT BINARY', str_repeat('d', 300)); 158 pdo_mysql_stmt_bindparam_types($db, 56, "ENUM('yes', 'no') DEFAULT 'yes'", "no"); 159 pdo_mysql_stmt_bindparam_types($db, 57, "SET('yes', 'no') DEFAULT 'yes'", "no"); 160 161 } catch (PDOException $e) { 162 printf("[001] %s [%s] %s\n", 163 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 164 } 165 166 print "done!"; 167?> 168--CLEAN-- 169<?php 170require __DIR__ . '/mysql_pdo_test.inc'; 171MySQLPDOTest::dropTestTable(); 172?> 173--EXPECT-- 174done! 175