1<?php 2 3/* 4V4.80 8 Mar 2006 (c) 2000-2009 John Lim (jlim#natsoft.com). All rights reserved. 5 Released under both BSD license and Lesser GPL library license. 6 Whenever there is any discrepancy between the two licenses, 7 the BSD license will take precedence. 8*/ 9 10 /* this file is used by the ADODB test program: test.php */ 11 ?> 12 13<table><tr valign=top><td> 14<form method=get> 15<input type=checkbox name="testaccess" value=1 <?php echo !empty($testaccess) ? 'checked' : '' ?>> <b>Access</b><br> 16<input type=checkbox name="testibase" value=1 <?php echo !empty($testibase) ? 'checked' : '' ?>> <b>Interbase</b><br> 17<input type=checkbox name="testmssql" value=1 <?php echo !empty($testmssql) ? 'checked' : '' ?>> <b>MSSQL</b><br> 18 <input type=checkbox name="testmysql" value=1 <?php echo !empty($testmysql) ? 'checked' : '' ?>> <b>MySQL</b><br> 19<input type=checkbox name="testmysqlodbc" value=1 <?php echo !empty($testmysqlodbc) ? 'checked' : '' ?>> <b>MySQL ODBC</b><br> 20<input type=checkbox name="testmysqli" value=1 <?php echo !empty($testmysqli) ? 'checked' : '' ?>> <b>MySQLi</b> 21<br> 22<td><input type=checkbox name="testsqlite" value=1 <?php echo !empty($testsqlite) ? 'checked' : '' ?>> <b>SQLite</b><br> 23<input type=checkbox name="testproxy" value=1 <?php echo !empty($testproxy) ? 'checked' : '' ?>> <b>MySQL Proxy</b><br> 24<input type=checkbox name="testoracle" value=1 <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br> 25<input type=checkbox name="testpostgres" value=1 <?php echo !empty($testpostgres) ? 'checked' : '' ?>> <b>PostgreSQL</b><br> 26<input type=checkbox name="testpgodbc" value=1 <?php echo !empty($testpgodbc) ? 'checked' : '' ?>> <b>PostgreSQL ODBC</b><br> 27<td> 28<input type=checkbox name="testpdopgsql" value=1 <?php echo !empty($testpdopgsql) ? 'checked' : '' ?>> <b>PgSQL PDO</b><br> 29<input type=checkbox name="testpdomysql" value=1 <?php echo !empty($testpdomysql) ? 'checked' : '' ?>> <b>MySQL PDO</b><br> 30<input type=checkbox name="testpdosqlite" value=1 <?php echo !empty($testpdosqlite) ? 'checked' : '' ?>> <b>SQLite PDO</b><br> 31<input type=checkbox name="testpdoaccess" value=1 <?php echo !empty($testpdoaccess) ? 'checked' : '' ?>> <b>Access PDO</b><br> 32<input type=checkbox name="testpdomssql" value=1 <?php echo !empty($testpdomssql) ? 'checked' : '' ?>> <b>MSSQL PDO</b><br> 33 34<input type=checkbox name="testpdoora" value=1 <?php echo !empty($testpdoora) ? 'checked' : '' ?>> <b>OCI PDO</b><br> 35 36<td><input type=checkbox name="testdb2" value=1 <?php echo !empty($testdb2) ? 'checked' : '' ?>> DB2<br> 37<input type=checkbox name="testvfp" value=1 <?php echo !empty($testvfp) ? 'checked' : '' ?>> VFP+ODBTP<br> 38<input type=checkbox name="testado" value=1 <?php echo !empty($testado) ? 'checked' : '' ?>> ADO (for mssql and access)<br> 39<input type=checkbox name="nocountrecs" value=1 <?php echo !empty($nocountrecs) ? 'checked' : '' ?>> $ADODB_COUNTRECS=false<br> 40<input type=checkbox name="nolog" value=1 <?php echo !empty($nolog) ? 'checked' : '' ?>> No SQL Logging<br> 41<input type=checkbox name="time" value=1 <?php echo !empty($_GET['time']) ? 'checked' : '' ?>> ADOdb time test 42</table> 43<input type=submit> 44</form> 45 46<?php 47 48if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>"; 49 50if (isset($nocountrecs)) $ADODB_COUNTRECS = false; 51 52// cannot test databases below, but we include them anyway to check 53// if they parse ok... 54 55if (sizeof($_GET) || !isset($_SERVER['HTTP_HOST'])) { 56 echo "<BR>"; 57 ADOLoadCode2("sybase"); 58 ADOLoadCode2("postgres"); 59 ADOLoadCode2("postgres7"); 60 ADOLoadCode2("firebird"); 61 ADOLoadCode2("borland_ibase"); 62 ADOLoadCode2("informix"); 63 ADOLoadCode2('mysqli'); 64 if (defined('ODBC_BINMODE_RETURN')) { 65 ADOLoadCode2("sqlanywhere"); 66 ADOLoadCode2("access"); 67 } 68 ADOLoadCode2("mysql"); 69 ADOLoadCode2("oci8"); 70} 71 72function ADOLoadCode2($d) 73{ 74 ADOLoadCode($d); 75 $c = ADONewConnection($d); 76 echo "Loaded $d ",($c ? 'ok' : 'extension not installed'),"<br>"; 77} 78 79flush(); 80if (!empty($testpostgres)) { 81 //ADOLoadCode("postgres"); 82 83 $db = ADONewConnection('postgres'); 84 print "<h1>Connecting $db->databaseType...</h1>"; 85 if ($db->Connect("localhost","tester","test","test")) { 86 testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)"); 87 }else 88 print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg(); 89} 90 91if (!empty($testpgodbc)) { 92 93 $db = ADONewConnection('odbc'); 94 $db->hasTransactions = false; 95 print "<h1>Connecting $db->databaseType...</h1>"; 96 97 if ($db->PConnect('Postgresql')) { 98 $db->hasTransactions = true; 99 testdb($db, 100 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb"); 101 } else print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg(); 102} 103 104if (!empty($testibase)) { 105 //$_GET['nolog'] = true; 106 $db = ADONewConnection('firebird'); 107 print "<h1>Connecting $db->databaseType...</h1>"; 108 if ($db->PConnect("localhost:d:\\firebird\\151\\examples\\EMPLOYEE.fdb", "sysdba", "masterkey", "")) 109 testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),price numeric(12,2),created date)"); 110 else print "ERROR: Interbase test requires a database called employee.gdb".'<BR>'.$db->ErrorMsg(); 111 112} 113 114 115if (!empty($testsqlite)) { 116 $path =urlencode('d:\inetpub\adodb\sqlite.db'); 117 $dsn = "sqlite://$path/"; 118 $db = ADONewConnection($dsn); 119 //echo $dsn; 120 121 //$db = ADONewConnection('sqlite'); 122 123 124 if ($db && $db->PConnect("d:\\inetpub\\adodb\\sqlite.db", "", "", "")) { 125 print "<h1>Connecting $db->databaseType...</h1>"; 126 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)"); 127 } else 128 print "ERROR: SQLite"; 129 130} 131 132if (!empty($testpdopgsql)) { 133 $connstr = "pgsql:dbname=test"; 134 $u = 'tester';$p='test'; 135 $db = ADONewConnection('pdo'); 136 print "<h1>Connecting $db->databaseType...</h1>"; 137 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 138 testdb($db, 139 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 140} 141 142if (!empty($testpdomysql)) { 143 $connstr = "mysql:dbname=northwind"; 144 $u = 'root';$p=''; 145 $db = ADONewConnection('pdo'); 146 print "<h1>Connecting $db->databaseType...</h1>"; 147 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 148 149 testdb($db, 150 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 151} 152 153if (!empty($testpdomssql)) { 154 $connstr = "mssql:dbname=northwind"; 155 $u = 'sa';$p='natsoft'; 156 $db = ADONewConnection('pdo'); 157 print "<h1>Connecting $db->databaseType...</h1>"; 158 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 159 160 testdb($db, 161 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 162} 163 164if (!empty($testpdosqlite)) { 165 $connstr = "sqlite:d:/inetpub/adodb/sqlite-pdo.db3"; 166 $u = '';$p=''; 167 $db = ADONewConnection('pdo'); 168 $db->hasTransactions = false; 169 print "<h1>Connecting $db->databaseType...</h1>"; 170 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 171 testdb($db, 172 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 173} 174 175if (!empty($testpdoaccess)) { 176 $connstr = 'odbc:nwind'; 177 $u = '';$p=''; 178 $db = ADONewConnection('pdo'); 179 $db->hasTransactions = false; 180 print "<h1>Connecting $db->databaseType...</h1>"; 181 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 182 testdb($db, 183 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 184} 185 186if (!empty($testpdoora)) { 187 $connstr = 'oci:'; 188 $u = 'scott';$p='natsoft'; 189 $db = ADONewConnection('pdo'); 190 #$db->hasTransactions = false; 191 print "<h1>Connecting $db->databaseType...</h1>"; 192 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED"); 193 testdb($db, 194 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 195} 196 197// REQUIRES ODBC DSN CALLED nwind 198if (!empty($testaccess)) { 199 $db = ADONewConnection('access'); 200 print "<h1>Connecting $db->databaseType...</h1>"; 201 $access = 'd:\inetpub\wwwroot\php\NWIND.MDB'; 202 $dsn = "nwind"; 203 $dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=$access;Uid=Admin;Pwd=;"; 204 205 //$dsn = 'Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=' . $access . ';'; 206 if ($db->PConnect($dsn, "", "", "")) 207 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)"); 208 else print "ERROR: Access test requires a Windows ODBC DSN=nwind, Access driver"; 209 210} 211 212if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS 213 214 $db = ADONewConnection("ado_access"); 215 print "<h1>Connecting $db->databaseType...</h1>"; 216 217 $access = 'd:\inetpub\wwwroot\php\NWIND.MDB'; 218 $myDSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;' 219 . 'DATA SOURCE=' . $access . ';'; 220 //. 'USER ID=;PASSWORD=;'; 221 $_GET['nolog'] = 1; 222 if ($db->PConnect($myDSN, "", "", "")) { 223 print "ADO version=".$db->_connectionID->version."<br>"; 224 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)"); 225 } else print "ERROR: Access test requires a Access database $access".'<BR>'.$db->ErrorMsg(); 226 227} 228 229if (!empty($testvfp)) { // ODBC 230 $db = ADONewConnection('vfp'); 231 print "<h1>Connecting $db->databaseType...</h1>";flush(); 232 233 if ( $db->PConnect("vfp-adoxyz")) { 234 testdb($db,"create table d:\\inetpub\\adodb\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)"); 235 } else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=vfp-adoxyz, VFP driver"; 236 237 echo "<hr />"; 238 $db = ADONewConnection('odbtp'); 239 240 if ( $db->PConnect('localhost','DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=d:\inetpub\adodb;EXCLUSIVE=NO;')) { 241 print "<h1>Connecting $db->databaseType...</h1>";flush(); 242 testdb($db,"create table d:\\inetpub\\adodb\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)"); 243 } else print "ERROR: Visual FoxPro odbtp requires a Windows ODBC DSN=vfp-adoxyz, VFP driver"; 244 245} 246 247 248// REQUIRES MySQL server at localhost with database 'test' 249if (!empty($testmysql)) { // MYSQL 250 251 252 if (PHP_VERSION >= 5 || $_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost'; 253 else $server = "mangrove"; 254 $user = 'root'; $password = ''; $database = 'northwind'; 255 $db = ADONewConnection("mysqlt://$user:$password@$server/$database?persist"); 256 print "<h1>Connecting $db->databaseType...</h1>"; 257 258 if (true || $db->PConnect($server, "root", "", "northwind")) { 259 //$db->Execute("DROP TABLE ADOXYZ") || die('fail drop'); 260 //$db->debug=1;$db->Execute('drop table ADOXYZ'); 261 testdb($db, 262 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) Type=InnoDB"); 263 } else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg(); 264} 265 266// REQUIRES MySQL server at localhost with database 'test' 267if (!empty($testmysqli)) { // MYSQL 268 269 $db = ADONewConnection('mysqli'); 270 print "<h1>Connecting $db->databaseType...</h1>"; 271 if (PHP_VERSION >= 5 || $_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost'; 272 else $server = "mangrove"; 273 if ($db->PConnect($server, "root", "", "northwind")) { 274 //$db->debug=1;$db->Execute('drop table ADOXYZ'); 275 testdb($db, 276 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)"); 277 } else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg(); 278} 279 280 281// REQUIRES MySQL server at localhost with database 'test' 282if (!empty($testmysqlodbc)) { // MYSQL 283 284 $db = ADONewConnection('odbc'); 285 $db->hasTransactions = false; 286 print "<h1>Connecting $db->databaseType...</h1>"; 287 if ($_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost'; 288 else $server = "mangrove"; 289 if ($db->PConnect('mysql', "root", "")) 290 testdb($db, 291 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb"); 292 else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg(); 293} 294 295if (!empty($testproxy)){ 296 $db = ADONewConnection('proxy'); 297 print "<h1>Connecting $db->databaseType...</h1>"; 298 if ($_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost'; 299 300 if ($db->PConnect('http://localhost/php/phplens/adodb/server.php')) 301 testdb($db, 302 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb"); 303 else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg(); 304 305} 306 307ADOLoadCode('oci805'); 308ADOLoadCode("oci8po"); 309 310if (!empty($testoracle)) { 311 $dsn = "oci8po";//://scott:natsoft@kk2?persist"; 312 $db = ADONewConnection($dsn );//'oci8'); 313 314 //$db->debug=1; 315 print "<h1>Connecting $db->databaseType...</h1>"; 316 if ($db->Connect('192.168.0.138', "scott", "natsoft",'SID=natsoft')) 317 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)"); 318 else 319 print "ERROR: Oracle test requires an Oracle server setup with scott/natsoft".'<BR>'.$db->ErrorMsg(); 320 321} 322ADOLoadCode("oracle"); // no longer supported 323if (false && !empty($testoracle)) { 324 325 $db = ADONewConnection(); 326 print "<h1>Connecting $db->databaseType...</h1>"; 327 if ($db->PConnect("", "scott", "tiger", "natsoft.domain")) 328 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)"); 329 else print "ERROR: Oracle test requires an Oracle server setup with scott/tiger".'<BR>'.$db->ErrorMsg(); 330 331} 332 333ADOLoadCode("odbc_db2"); // no longer supported 334if (!empty($testdb2)) { 335 if (PHP_VERSION>=5.1) { 336 $db = ADONewConnection("db2"); 337 print "<h1>Connecting $db->databaseType...</h1>"; 338 339 #$db->curMode = SQL_CUR_USE_ODBC; 340 #$dsn = "driver={IBM db2 odbc DRIVER};Database=test;hostname=localhost;port=50000;protocol=TCPIP; uid=natsoft; pwd=guest"; 341 if ($db->Connect('localhost','natsoft','guest','test')) { 342 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)"); 343 } else print "ERROR: DB2 test requires an server setup with odbc data source db2_sample".'<BR>'.$db->ErrorMsg(); 344 } else { 345 $db = ADONewConnection("odbc_db2"); 346 print "<h1>Connecting $db->databaseType...</h1>"; 347 348 $dsn = "db2test"; 349 #$db->curMode = SQL_CUR_USE_ODBC; 350 #$dsn = "driver={IBM db2 odbc DRIVER};Database=test;hostname=localhost;port=50000;protocol=TCPIP; uid=natsoft; pwd=guest"; 351 if ($db->Connect($dsn)) { 352 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)"); 353 } else print "ERROR: DB2 test requires an server setup with odbc data source db2_sample".'<BR>'.$db->ErrorMsg(); 354 } 355echo "<hr />"; 356flush(); 357 $dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP; uid=root; pwd=natsoft"; 358 359 $db = ADONewConnection('odbtp'); 360 if ($db->Connect('127.0.0.1',$dsn)) { 361 362 $db->debug=1; 363 $arr = $db->GetArray( "||SQLProcedures" ); adodb_pr($arr); 364 $arr = $db->GetArray( "||SQLProcedureColumns|||GET_ROUTINE_SAR" );adodb_pr($arr); 365 366 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)"); 367 } else echo ("ERROR Connection"); 368 echo $db->ErrorMsg(); 369} 370 371 372$server = 'localhost'; 373 374 375 376ADOLoadCode("mssqlpo"); 377if (false && !empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC 378 $db = ADONewConnection("mssqlpo"); 379 //$db->debug=1; 380 print "<h1>Connecting $db->databaseType...</h1>"; 381 382 $ok = $db->Connect('','sa','natsoft','northwind'); 383 echo $db->ErrorMsg(); 384 if ($ok /*or $db->PConnect("mangrove", "sa", "natsoft", "ai")*/) { 385 AutoDetect_MSSQL_Date_Order($db); 386 // $db->Execute('drop table adoxyz'); 387 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)"); 388 } else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='$server', userid='adodb', password='natsoft', database='ai'".'<BR>'.$db->ErrorMsg(); 389 390} 391 392 393ADOLoadCode('odbc_mssql'); 394if (!empty($testmssql)) { // MS SQL Server via ODBC 395 $db = ADONewConnection(); 396 397 print "<h1>Connecting $db->databaseType...</h1>"; 398 399 $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;"; 400 $dsn = 'condor'; 401 if ($db->PConnect($dsn, "sa", "natsoft", "")) { 402 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)"); 403 } 404 else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup"; 405 406} 407 408ADOLoadCode("ado_mssql"); 409if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less 410 411 $db = ADONewConnection("ado_mssql"); 412 //$db->debug=1; 413 print "<h1>Connecting DSN-less $db->databaseType...</h1>"; 414 415 $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};" 416 . "SERVER=$server;DATABASE=NorthWind;UID=adodb;PWD=natsoft;Trusted_Connection=No"; 417 418 419 if ($db->PConnect($myDSN, "", "", "")) 420 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)"); 421 else print "ERROR: MSSQL test 2 requires MS SQL 7"; 422 423} 424 425if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB provider 426 427 $db = ADONewConnection("ado_mssql"); 428 print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>"; 429 //$db->debug=1; 430 $myDSN="SERVER=localhost;DATABASE=northwind;Trusted_Connection=yes"; 431 if ($db->PConnect($myDSN, "adodb", "natsoft", 'SQLOLEDB')) { 432 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)"); 433 } else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='mangrove', userid='sa', password='', database='ai'"; 434 435} 436 437 438if (extension_loaded('odbtp') && !empty($testmssql)) { // MS SQL Server via ODBC 439 $db = ADONewConnection('odbtp'); 440 441 $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;uid=adodb;pwd=natsoft"; 442 443 if ($db->PConnect('localhost',$dsn, "", "")) { 444 print "<h1>Connecting $db->databaseType...</h1>"; 445 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)"); 446 } 447 else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup"; 448 449} 450 451 452print "<h3>Tests Completed</h3>"; 453 454?> 455