[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 3 /** 4 * Local error callback handler. 5 * 6 * Drops the phptest table, prints out an error message and kills the 7 * process. 8 * 9 * @param object $o PEAR error object automatically passed to this method 10 * @return void 11 * @see PEAR::setErrorHandling() 12 */ 13 function pe($o) { 14 global $dbh; 15 16 $dbh->setErrorHandling(PEAR_ERROR_RETURN); 17 $dbh->query('DROP TABLE phptest'); 18 19 die($o->toString()); 20 } 21 22 $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe'); 23 24 25 $dbh->query("INSERT INTO phptest VALUES (1, 'one', 'One', '2001-02-16')"); 26 $dbh->query("INSERT INTO phptest VALUES (2, 'two', 'Two', '2001-02-15')"); 27 $dbh->query("INSERT INTO phptest VALUES (3, 'three', 'Three', '2001-02-14')"); 28 29 print "testing fetchrow:\n"; 30 $sth = $dbh->query("SELECT * FROM phptest"); 31 for ($i = 1; $i <= 5; $i++) { 32 print "row $i: "; 33 $row = $sth->fetchRow(); 34 if (DB::isError($row)) { 35 print $row->toString() . "\n"; 36 continue; 37 } 38 if (is_array($row)) { 39 print implode(', ', $row) . "\n"; 40 } else { 41 var_dump($row); 42 } 43 } 44 45 $dbh->query('DELETE FROM phptest WHERE a <> 42'); 46 47 48 print "testing fetchmodes: fetchrow default default, portability mode DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM\n"; 49 $dbh->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM); 50 $sth = $dbh->query("SELECT * FROM phptest"); 51 $row = $sth->fetchRow(); 52 print implode(" ", array_keys($row))."\n"; 53 $actual = implode(' ', array_values($row)); 54 switch ($dbh->phptype) { 55 case 'mysql': 56 case 'mysqli': 57 case 'sqlite': 58 $expected = '42 bing This is a test 1999-11-21'; 59 break; 60 case 'ifx': 61 $expected = '42 bing This is a test 1999-11-21 '; 62 break; 63 default: 64 $expected = '42 bing This is a test 1999-11-21'; 65 } 66 if ($actual == $expected) { 67 echo "output matched expected format\n"; 68 } else { 69 echo "DIDN'T MATCH! Expected output: '$expected'. Actual output: '$actual'.\n"; 70 } 71 72 print "testing fetchmodes: fetchinto default default\n"; 73 $dbh->setOption('portability', DB_PORTABILITY_ALL); 74 $sth = $dbh->query("SELECT * FROM phptest"); 75 $row = array(); 76 $sth->fetchInto($row); 77 print implode(" ", array_keys($row))."\n"; 78 print implode(' ', array_values($row))."\n"; 79 80 print "testing fetchmodes: fetchrow ordered default\n"; 81 $dbh->setFetchMode(DB_FETCHMODE_ORDERED); 82 $sth = $dbh->query("SELECT * FROM phptest"); 83 $row = $sth->fetchRow(); 84 print implode(" ", array_keys($row))."\n"; 85 86 print "testing fetchmodes: fetchrow assoc default\n"; 87 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 88 $sth = $dbh->query("SELECT * FROM phptest"); 89 $row = $sth->fetchRow(); 90 print implode(" ", array_keys($row))."\n"; 91 92 print "testing fetchmodes: fetchrow ordered default with assoc specified\n"; 93 $dbh->setFetchMode(DB_FETCHMODE_ORDERED); 94 $sth = $dbh->query("SELECT * FROM phptest"); 95 $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); 96 print implode(" ", array_keys($row))."\n"; 97 98 print "testing fetchmodes: fetchrow assoc default with ordered specified\n"; 99 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 100 $sth = $dbh->query("SELECT * FROM phptest"); 101 $row = $sth->fetchRow(DB_FETCHMODE_ORDERED); 102 print implode(" ", array_keys($row))."\n"; 103 104 print "testing fetchmodes: fetchinto ordered default\n"; 105 $dbh->setFetchMode(DB_FETCHMODE_ORDERED); 106 $sth = $dbh->query("SELECT * FROM phptest"); 107 $row = array(); 108 $sth->fetchInto($row); 109 print implode(" ", array_keys($row))."\n"; 110 111 print "testing fetchmodes: fetchinto assoc default\n"; 112 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 113 $sth = $dbh->query("SELECT * FROM phptest"); 114 $row = array(); 115 $sth->fetchInto($row); 116 print implode(" ", array_keys($row))."\n"; 117 118 print "testing fetchmodes: fetchinto ordered default with assoc specified\n"; 119 $dbh->setFetchMode(DB_FETCHMODE_ORDERED); 120 $sth = $dbh->query("SELECT * FROM phptest"); 121 $row = array(); 122 $sth->fetchInto($row, DB_FETCHMODE_ASSOC); 123 print implode(" ", array_keys($row))."\n"; 124 125 print "testing fetchmodes: fetchinto assoc default with ordered specified\n"; 126 $dbh->setFetchMode(DB_FETCHMODE_ASSOC); 127 $sth = $dbh->query("SELECT * FROM phptest"); 128 $row = array(); 129 $sth->fetchInto($row, DB_FETCHMODE_ORDERED); 130 print implode(" ", array_keys($row))."\n"; 131 132 switch ($dbh->phptype) { 133 case 'ibase': 134 /* 135 * Interbase doesn't allow dropping tables that have result 136 * sets still open. 137 */ 138 $dbh->freeResult($sth->result); 139 break; 140 } 141 $dbh->setErrorHandling(PEAR_ERROR_RETURN); 142 $dbh->query('DROP TABLE phptest'); 143 144 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |