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