1--TEST-- 2PDO Common: PDO::FETCH_BOUND w/o : 3--EXTENSIONS-- 4pdo 5--SKIPIF-- 6<?php 7$dir = getenv('REDIR_TEST_DIR'); 8if (false == $dir) die('skip no driver'); 9require_once $dir . 'pdo_test.inc'; 10if (!strncasecmp(getenv('PDOTEST_DSN'), 'oci', strlen('oci'))) die('skip not relevant for oci driver - cannot reexecute after closing cursors without reparse'); 11PDOTest::skip(); 12?> 13--FILE-- 14<?php 15if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); 16require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 17$db = PDOTest::factory(); 18 19if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { 20 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 21} 22 23$db->exec('CREATE TABLE test016a(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))'); 24$db->exec("INSERT INTO test016a VALUES(0, 'String0')"); 25$db->exec("INSERT INTO test016a VALUES(1, 'String1')"); 26$db->exec("INSERT INTO test016a VALUES(2, 'String2')"); 27 28$stmt1 = $db->prepare('SELECT COUNT(idx) FROM test016a'); 29$stmt2 = $db->prepare('SELECT idx, txt FROM test016a ORDER by idx'); 30 31$stmt1->execute(); 32var_dump($stmt1->fetchColumn()); 33$stmt1 = null; 34 35$stmt2->execute(); 36$cont = $stmt2->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); 37var_dump($cont); 38 39echo "===WHILE===\n"; 40 41$stmt2->bindColumn('idx', $idx); 42$stmt2->bindColumn('txt', $txt); 43$stmt2->execute(); 44 45while($stmt2->fetch(PDO::FETCH_BOUND)) { 46 var_dump(array($idx=>$txt)); 47} 48 49echo "===ALONE===\n"; 50 51$stmt3 = $db->prepare('SELECT txt FROM test016a WHERE idx=:inp'); 52$stmt3->bindParam('inp', $idx); /* by foreign name */ 53 54$stmt4 = $db->prepare('SELECT idx FROM test016a WHERE txt=:txt'); 55$stmt4->bindParam('txt', $txt); /* using same name */ 56 57foreach($cont as $idx => $txt) 58{ 59 var_dump(array($idx=>$txt)); 60 var_dump($stmt3->execute()); 61 62 if ($idx == 0) { 63 /* portability-wise, you may only bindColumn()s 64 * after execute() has been called at least once */ 65 $stmt3->bindColumn('txt', $col1); 66 } 67 var_dump($stmt3->fetch(PDO::FETCH_BOUND)); 68 $stmt3->closeCursor(); 69 70 var_dump($stmt4->execute()); 71 if ($idx == 0) { 72 /* portability-wise, you may only bindColumn()s 73 * after execute() has been called at least once */ 74 $stmt4->bindColumn('idx', $col2); 75 } 76 var_dump($stmt4->fetch(PDO::FETCH_BOUND)); 77 $stmt4->closeCursor(); 78 var_dump(array($col2=>$col1)); 79} 80 81echo "===REBIND/SAME===\n"; 82 83$stmt4->bindColumn('idx', $col1); 84 85foreach($cont as $idx => $txt) 86{ 87 var_dump(array($idx=>$txt)); 88 var_dump($stmt3->execute()); 89 var_dump($stmt3->fetch(PDO::FETCH_BOUND)); 90 $stmt3->closeCursor(); 91 var_dump($col1); 92 var_dump($stmt4->execute()); 93 var_dump($stmt4->fetch(PDO::FETCH_BOUND)); 94 $stmt4->closeCursor(); 95 var_dump($col1); 96} 97 98echo "===REBIND/CONFLICT===\n"; 99 100$stmt2->bindColumn('idx', $col1); 101$stmt2->bindColumn('txt', $col1); 102$stmt2->execute(); 103 104while($stmt2->fetch(PDO::FETCH_BOUND)) 105{ 106 var_dump($col1); 107} 108 109 110?> 111--CLEAN-- 112<?php 113require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 114$db = PDOTest::factory(); 115PDOTest::dropTableIfExists($db, "test016a"); 116?> 117--EXPECT-- 118string(1) "3" 119array(3) { 120 [0]=> 121 string(7) "String0" 122 [1]=> 123 string(7) "String1" 124 [2]=> 125 string(7) "String2" 126} 127===WHILE=== 128array(1) { 129 [0]=> 130 string(7) "String0" 131} 132array(1) { 133 [1]=> 134 string(7) "String1" 135} 136array(1) { 137 [2]=> 138 string(7) "String2" 139} 140===ALONE=== 141array(1) { 142 [0]=> 143 string(7) "String0" 144} 145bool(true) 146bool(true) 147bool(true) 148bool(true) 149array(1) { 150 [0]=> 151 string(7) "String0" 152} 153array(1) { 154 [1]=> 155 string(7) "String1" 156} 157bool(true) 158bool(true) 159bool(true) 160bool(true) 161array(1) { 162 [1]=> 163 string(7) "String1" 164} 165array(1) { 166 [2]=> 167 string(7) "String2" 168} 169bool(true) 170bool(true) 171bool(true) 172bool(true) 173array(1) { 174 [2]=> 175 string(7) "String2" 176} 177===REBIND/SAME=== 178array(1) { 179 [0]=> 180 string(7) "String0" 181} 182bool(true) 183bool(true) 184string(7) "String0" 185bool(true) 186bool(true) 187string(1) "0" 188array(1) { 189 [1]=> 190 string(7) "String1" 191} 192bool(true) 193bool(true) 194string(7) "String1" 195bool(true) 196bool(true) 197string(1) "1" 198array(1) { 199 [2]=> 200 string(7) "String2" 201} 202bool(true) 203bool(true) 204string(7) "String2" 205bool(true) 206bool(true) 207string(1) "2" 208===REBIND/CONFLICT=== 209string(7) "String0" 210string(7) "String1" 211string(7) "String2" 212