4 V4.80 8 Mar 2006 (c) 2000-2012 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.
10 /* this file is used by the ADODB test program: test.php */
13 <table><tr valign=top><td>
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>
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>
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>
34 <input type=checkbox name="testpdoora" value=1 <?php echo !empty($testpdoora) ? 'checked' : '' ?>> <b>OCI PDO</b><br>
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
48 if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>";
50 if (isset($nocountrecs)) $ADODB_COUNTRECS = false;
52 // cannot test databases below, but we include them anyway to check
53 // if they parse ok...
55 if (sizeof($_GET) || !isset($_SERVER['HTTP_HOST'])) {
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");
68 ADOLoadCode2("mysql");
72 function ADOLoadCode2($d)
75 $c = ADONewConnection($d);
76 echo "Loaded $d ",($c ? 'ok' : 'extension not installed'),"<br>";
80 if (!empty($testpostgres)) {
81 //ADOLoadCode("postgres");
83 $db = ADONewConnection('postgres');
84 print "<h1>Connecting $db->databaseType...</h1>";
85 if ($db->Connect("localhost","tester","test","northwind")) {
86 testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)");
88 print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg();
91 if (!empty($testpgodbc)) {
93 $db = ADONewConnection('odbc');
94 $db->hasTransactions = false;
95 print "<h1>Connecting $db->databaseType...</h1>";
97 if ($db->PConnect('Postgresql')) {
98 $db->hasTransactions = true;
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();
104 if (!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();
115 if (!empty($testsqlite)) {
116 $path =urlencode('d:\inetpub\adodb\sqlite.db');
117 $dsn = "sqlite://$path/";
118 $db = ADONewConnection($dsn);
121 //$db = ADONewConnection('sqlite');
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)");
128 print "ERROR: SQLite";
132 if (!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");
139 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
142 if (!empty($testpdomysql)) {
143 $connstr = "mysql:dbname=northwind";
145 $db = ADONewConnection('pdo');
146 print "<h1>Connecting $db->databaseType...</h1>";
147 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
150 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
153 if (!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");
161 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
164 if (!empty($testpdosqlite)) {
165 $connstr = "sqlite:d:/inetpub/adodb/sqlite-pdo.db3";
167 $db = ADONewConnection('pdo');
168 $db->hasTransactions = false;
169 print "<h1>Connecting $db->databaseType...</h1>";
170 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
172 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
175 if (!empty($testpdoaccess)) {
176 $connstr = 'odbc:nwind';
178 $db = ADONewConnection('pdo');
179 $db->hasTransactions = false;
180 print "<h1>Connecting $db->databaseType...</h1>";
181 $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
183 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
186 if (!empty($testpdoora)) {
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");
194 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
197 // REQUIRES ODBC DSN CALLED nwind
198 if (!empty($testaccess)) {
199 $db = ADONewConnection('access');
200 print "<h1>Connecting $db->databaseType...</h1>";
201 $access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
203 $dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=$access;Uid=Admin;Pwd=;";
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";
212 if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS
214 $db = ADONewConnection("ado_access");
215 print "<h1>Connecting $db->databaseType...</h1>";
217 $access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
218 $myDSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;'
219 . 'DATA SOURCE=' . $access . ';';
220 //. 'USER ID=;PASSWORD=;';
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();
229 if (!empty($testvfp)) { // ODBC
230 $db = ADONewConnection('vfp');
231 print "<h1>Connecting $db->databaseType...</h1>";flush();
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";
238 $db = ADONewConnection('odbtp');
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";
248 // REQUIRES MySQL server at localhost with database 'test'
249 if (!empty($testmysql)) { // MYSQL
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>";
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');
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();
266 // REQUIRES MySQL server at localhost with database 'test'
267 if (!empty($testmysqli)) { // MYSQL
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');
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();
281 // REQUIRES MySQL server at localhost with database 'test'
282 if (!empty($testmysqlodbc)) { // MYSQL
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", ""))
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();
295 if (!empty($testproxy)){
296 $db = ADONewConnection('proxy');
297 print "<h1>Connecting $db->databaseType...</h1>";
298 if ($_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost';
300 if ($db->PConnect('http://localhost/php/phplens/adodb/server.php'))
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();
307 ADOLoadCode('oci805');
308 ADOLoadCode("oci8po");
310 if (!empty($testoracle)) {
311 $dsn = "oci8";//://scott:natsoft@kk2?persist";
312 $db = ADONewConnection($dsn );//'oci8');
315 print "<h1>Connecting $db->databaseType...</h1>";
316 if ($db->Connect('mobydick', "scott", "natsoft",'SID=mobydick'))
317 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
319 print "ERROR: Oracle test requires an Oracle server setup with scott/natsoft".'<BR>'.$db->ErrorMsg();
322 ADOLoadCode("oracle"); // no longer supported
323 if (false && !empty($testoracle)) {
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();
333 ADOLoadCode("odbc_db2"); // no longer supported
334 if (!empty($testdb2)) {
335 if (PHP_VERSION>=5.1) {
336 $db = ADONewConnection("db2");
337 print "<h1>Connecting $db->databaseType...</h1>";
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();
345 $db = ADONewConnection("odbc_db2");
346 print "<h1>Connecting $db->databaseType...</h1>";
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();
357 $dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP; uid=root; pwd=natsoft";
359 $db = ADONewConnection('odbtp');
360 if ($db->Connect('127.0.0.1',$dsn)) {
363 $arr = $db->GetArray( "||SQLProcedures" ); adodb_pr($arr);
364 $arr = $db->GetArray( "||SQLProcedureColumns|||GET_ROUTINE_SAR" );adodb_pr($arr);
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();
372 $server = 'localhost';
376 ADOLoadCode("mssqlpo");
377 if (false && !empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC
378 $db = ADONewConnection("mssqlpo");
380 print "<h1>Connecting $db->databaseType...</h1>";
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();
393 ADOLoadCode('odbc_mssql');
394 if (!empty($testmssql)) { // MS SQL Server via ODBC
395 $db = ADONewConnection();
397 print "<h1>Connecting $db->databaseType...</h1>";
399 $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;";
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)");
404 else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup";
408 ADOLoadCode("ado_mssql");
409 if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less
411 $db = ADONewConnection("ado_mssql");
413 print "<h1>Connecting DSN-less $db->databaseType...</h1>";
415 $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"
416 . "SERVER=$server;DATABASE=NorthWind;UID=adodb;PWD=natsoft;Trusted_Connection=No";
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";
425 if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB provider
427 $db = ADONewConnection("ado_mssql");
428 print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>";
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'";
438 if (extension_loaded('odbtp') && !empty($testmssql)) { // MS SQL Server via ODBC
439 $db = ADONewConnection('odbtp');
441 $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;uid=adodb;pwd=natsoft";
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)");
447 else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup";
452 print "<h3>Tests Completed</h3>";