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