Documentation TYPO3 par Ameos

testdatabases.inc.php

00001 <?php
00002   
00003 /*
00004 V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
00005   Released under both BSD license and Lesser GPL library license. 
00006   Whenever there is any discrepancy between the two licenses, 
00007   the BSD license will take precedence.
00008 */ 
00009  
00010  /* this file is used by the ADODB test program: test.php */
00011  ?>
00012 
00013 <table><tr valign=top><td>
00014 <form method=get>
00015 <input type=checkbox name="testaccess" value=1 <?php echo !empty($testaccess) ? 'checked' : '' ?>> <b>Access</b><br>
00016 <input type=checkbox name="testibase" value=1 <?php echo !empty($testibase) ? 'checked' : '' ?>> <b>Interbase</b><br>
00017 <input type=checkbox name="testmssql" value=1 <?php echo !empty($testmssql) ? 'checked' : '' ?>> <b>MSSQL</b><br>
00018  <input type=checkbox name="testmysql" value=1 <?php echo !empty($testmysql) ? 'checked' : '' ?>> <b>MySQL</b><br>
00019 <input type=checkbox name="testmysqlodbc" value=1 <?php echo !empty($testmysqlodbc) ? 'checked' : '' ?>> <b>MySQL ODBC</b><br>
00020 <input type=checkbox name="testmysqli" value=1 <?php echo !empty($testmysqli) ? 'checked' : '' ?>> <b>MySQLi</b>
00021 <br>
00022 <td><input type=checkbox name="testsqlite" value=1 <?php echo !empty($testsqlite) ? 'checked' : '' ?>> <b>SQLite</b><br>
00023 <input type=checkbox name="testproxy" value=1 <?php echo !empty($testproxy) ? 'checked' : '' ?>> <b>MySQL Proxy</b><br>
00024 <input type=checkbox name="testoracle" value=1 <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br>
00025 <input type=checkbox name="testpostgres" value=1 <?php echo !empty($testpostgres) ? 'checked' : '' ?>> <b>PostgreSQL</b><br>
00026 <input type=checkbox name="testpgodbc" value=1 <?php echo !empty($testpgodbc) ? 'checked' : '' ?>> <b>PostgreSQL ODBC</b><br>
00027 <td>
00028 <input type=checkbox name="testpdopgsql" value=1 <?php echo !empty($testpdopgsql) ? 'checked' : '' ?>> <b>PgSQL PDO</b><br>
00029 <input type=checkbox name="testpdomysql" value=1 <?php echo !empty($testpdomysql) ? 'checked' : '' ?>> <b>MySQL PDO</b><br>
00030 <input type=checkbox name="testpdosqlite" value=1 <?php echo !empty($testpdosqlite) ? 'checked' : '' ?>> <b>SQLite PDO</b><br>
00031 <input type=checkbox name="testpdoaccess" value=1 <?php echo !empty($testpdoaccess) ? 'checked' : '' ?>> <b>Access PDO</b><br>
00032 <input type=checkbox name="testpdomssql" value=1 <?php echo !empty($testpdomssql) ? 'checked' : '' ?>> <b>MSSQL PDO</b><br>
00033 
00034 <input type=checkbox name="testpdoora" value=1 <?php echo !empty($testpdoora) ? 'checked' : '' ?>> <b>OCI PDO</b><br>
00035 
00036 <td><input type=checkbox name="testdb2" value=1 <?php echo !empty($testdb2) ? 'checked' : '' ?>> DB2<br>
00037 <input type=checkbox name="testvfp" value=1 <?php echo !empty($testvfp) ? 'checked' : '' ?>> VFP+ODBTP<br>
00038 <input type=checkbox name="testado" value=1 <?php echo !empty($testado) ? 'checked' : '' ?>> ADO (for mssql and access)<br>
00039 <input type=checkbox name="nocountrecs" value=1 <?php echo !empty($nocountrecs) ? 'checked' : '' ?>> $ADODB_COUNTRECS=false<br>
00040 <input type=checkbox name="nolog" value=1 <?php echo !empty($nolog) ? 'checked' : '' ?>> No SQL Logging<br>
00041 <input type=checkbox name="time" value=1 <?php echo !empty($_GET['time']) ? 'checked' : '' ?>> ADOdb time test
00042 </table>
00043 <input type=submit>
00044 </form>
00045 
00046 <?php
00047 
00048 if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>";
00049 
00050 if (isset($nocountrecs)) $ADODB_COUNTRECS = false;
00051 
00052 // cannot test databases below, but we include them anyway to check
00053 // if they parse ok...
00054 
00055 if (!strpos(PHP_VERSION,'5') === 0) {
00056         ADOLoadCode("sybase");
00057         //ADOLoadCode("postgres");
00058         //ADOLoadCode("postgres7");
00059         ADOLoadCode("firebird");
00060         ADOLoadCode("borland_ibase");
00061         ADOLoadCode("informix");
00062         ADOLoadCode("sqlanywhere");
00063 //      ADOLoadCode('mysqli');
00064 }
00065 
00066 
00067 flush();
00068 if (!empty($testpostgres)) {
00069         //ADOLoadCode("postgres");
00070 
00071         $db = &ADONewConnection('postgres');
00072         print "<h1>Connecting $db->databaseType...</h1>";
00073         if ($db->Connect("localhost","tester","test","test")) {
00074                 testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)");
00075         }else
00076                 print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg();
00077 }
00078 
00079 if (!empty($testpgodbc)) { 
00080         
00081         $db = &ADONewConnection('odbc');
00082         $db->hasTransactions = false;
00083         print "<h1>Connecting $db->databaseType...</h1>";
00084         
00085         if ($db->PConnect('Postgresql')) {
00086                 $db->hasTransactions = true;
00087                 testdb($db,
00088                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
00089         } else print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg();
00090 }
00091 
00092 if (!empty($testibase)) {
00093         //$_GET['nolog'] = true;
00094         $db = &ADONewConnection('firebird');
00095         print "<h1>Connecting $db->databaseType...</h1>";
00096         if ($db->PConnect("localhost:d:\\firebird\\151\\examples\\EMPLOYEE.fdb", "sysdba", "masterkey", ""))
00097                 testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),price numeric(12,2),created date)");
00098          else print "ERROR: Interbase test requires a database called employee.gdb".'<BR>'.$db->ErrorMsg();
00099         
00100 }
00101 
00102 
00103 if (!empty($testsqlite)) {
00104         $path =urlencode('d:\inetpub\adodb\sqlite.db');
00105         $dsn = "sqlite://$path/";
00106         $db = ADONewConnection($dsn);
00107         //echo $dsn;
00108         
00109         //$db = &ADONewConnection('sqlite');
00110         
00111 
00112         if ($db && $db->PConnect("d:\\inetpub\\adodb\\sqlite.db", "", "", "")) {
00113                 print "<h1>Connecting $db->databaseType...</h1>";
00114                 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
00115         } else 
00116                 print "ERROR: SQLite";
00117         
00118 }
00119 
00120 if (!empty($testpdopgsql)) {
00121         $connstr = "pgsql:dbname=test";
00122         $u = 'tester';$p='test';
00123         $db = &ADONewConnection('pdo');
00124         print "<h1>Connecting $db->databaseType...</h1>";
00125         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00126         testdb($db,
00127                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00128 }
00129 
00130 if (!empty($testpdomysql)) {
00131         $connstr = "mysql:dbname=northwind";
00132         $u = 'root';$p='';
00133         $db = &ADONewConnection('pdo');
00134         print "<h1>Connecting $db->databaseType...</h1>";
00135         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00136         
00137         testdb($db,
00138                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00139 }
00140 
00141 if (!empty($testpdomssql)) {
00142         $connstr = "mssql:dbname=northwind";
00143         $u = 'sa';$p='natsoft';
00144         $db = &ADONewConnection('pdo');
00145         print "<h1>Connecting $db->databaseType...</h1>";
00146         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00147         
00148         testdb($db,
00149                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00150 }
00151 
00152 if (!empty($testpdosqlite)) {
00153         $connstr = "sqlite:d:/inetpub/adodb/sqlite-pdo.db3";
00154         $u = '';$p='';
00155         $db = &ADONewConnection('pdo');
00156         $db->hasTransactions = false;
00157         print "<h1>Connecting $db->databaseType...</h1>";
00158         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00159         testdb($db,
00160                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00161 }
00162 
00163 if (!empty($testpdoaccess)) {
00164         $connstr = 'odbc:nwind';
00165         $u = '';$p='';
00166         $db = &ADONewConnection('pdo');
00167         $db->hasTransactions = false;
00168         print "<h1>Connecting $db->databaseType...</h1>";
00169         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00170         testdb($db,
00171                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00172 }
00173 
00174 if (!empty($testpdoora)) {
00175         $connstr = 'oci:';
00176         $u = 'scott';$p='natsoft';
00177         $db = &ADONewConnection('pdo');
00178         #$db->hasTransactions = false;
00179         print "<h1>Connecting $db->databaseType...</h1>";
00180         $db->Connect($connstr,$u,$p) || die("CONNECT FAILED");
00181         testdb($db,
00182                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00183 }
00184 
00185 // REQUIRES ODBC DSN CALLED nwind
00186 if (!empty($testaccess)) {
00187         $db = &ADONewConnection('access');
00188         print "<h1>Connecting $db->databaseType...</h1>";
00189         $access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
00190         $dsn = "nwind";
00191         $dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=$access;Uid=Admin;Pwd=;";
00192         
00193         //$dsn =  'Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=' . $access . ';';
00194         if ($db->PConnect($dsn, "", "", ""))
00195                 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
00196         else print "ERROR: Access test requires a Windows ODBC DSN=nwind, Access driver";
00197         
00198 }
00199 
00200 if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS
00201 
00202         $db = &ADONewConnection("ado_access");
00203         print "<h1>Connecting $db->databaseType...</h1>";
00204         
00205         $access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
00206         $myDSN =  'PROVIDER=Microsoft.Jet.OLEDB.4.0;'
00207                 . 'DATA SOURCE=' . $access . ';';
00208                 //. 'USER ID=;PASSWORD=;';
00209         $_GET['nolog'] = 1;
00210         if ($db->PConnect($myDSN, "", "", "")) {
00211                 print "ADO version=".$db->_connectionID->version."<br>";
00212                 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
00213         } else print "ERROR: Access test requires a Access database $access".'<BR>'.$db->ErrorMsg();
00214         
00215 }
00216 
00217 if (!empty($testvfp)) { // ODBC
00218         $db = &ADONewConnection('vfp');
00219         print "<h1>Connecting $db->databaseType...</h1>";flush();
00220 
00221         if ( $db->PConnect("vfp-adoxyz")) {
00222                 testdb($db,"create table d:\\inetpub\\adodb\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");
00223          } else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=vfp-adoxyz, VFP driver";
00224         
00225         echo "<hr />";
00226         $db = &ADONewConnection('odbtp');
00227         
00228         if ( $db->PConnect('localhost','DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=d:\inetpub\adodb;EXCLUSIVE=NO;')) {
00229         print "<h1>Connecting $db->databaseType...</h1>";flush();
00230         testdb($db,"create table d:\\inetpub\\adodb\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");
00231          } else print "ERROR: Visual FoxPro odbtp requires a Windows ODBC DSN=vfp-adoxyz, VFP driver";
00232         
00233 }
00234 
00235 
00236 // REQUIRES MySQL server at localhost with database 'test'
00237 if (!empty($testmysql)) { // MYSQL
00238 
00239 
00240         if (PHP_VERSION >= 5 || $_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost';
00241         else $server = "mangrove";
00242         $user = 'root'; $password = ''; $database = 'northwind';
00243         $db = &ADONewConnection("mysqlt://$user:$password@$server/$database?persist");
00244         print "<h1>Connecting $db->databaseType...</h1>";
00245         
00246         if (true || $db->PConnect($server, "root", "", "northwind")) {
00247                 //$db->Execute("DROP TABLE ADOXYZ") || die('fail drop');
00248                 //$db->debug=1;$db->Execute('drop table ADOXYZ');
00249                 testdb($db,
00250                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) Type=InnoDB");
00251         } else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
00252 }
00253 
00254 // REQUIRES MySQL server at localhost with database 'test'
00255 if (!empty($testmysqli)) { // MYSQL
00256 
00257         $db = &ADONewConnection('mysqli');
00258         print "<h1>Connecting $db->databaseType...</h1>";
00259         if (PHP_VERSION >= 5 || $_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost';
00260         else $server = "mangrove";
00261         if ($db->PConnect($server, "root", "", "northwind")) {
00262                 //$db->debug=1;$db->Execute('drop table ADOXYZ');
00263                 testdb($db,
00264                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
00265         } else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
00266 }
00267 
00268 
00269 // REQUIRES MySQL server at localhost with database 'test'
00270 if (!empty($testmysqlodbc)) { // MYSQL
00271         
00272         $db = &ADONewConnection('odbc');
00273         $db->hasTransactions = false;
00274         print "<h1>Connecting $db->databaseType...</h1>";
00275         if ($_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost';
00276         else $server = "mangrove";
00277         if ($db->PConnect('mysql', "root", ""))
00278                 testdb($db,
00279                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
00280         else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
00281 }
00282 
00283 if (!empty($testproxy)){
00284         $db = &ADONewConnection('proxy');
00285         print "<h1>Connecting $db->databaseType...</h1>";
00286         if ($_SERVER['HTTP_HOST'] == 'localhost') $server = 'localhost';
00287 
00288         if ($db->PConnect('http://localhost/php/phplens/adodb/server.php'))
00289                 testdb($db,
00290                 "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
00291         else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
00292 
00293 }
00294 
00295 ADOLoadCode('oci805');
00296 ADOLoadCode("oci8po");
00297 if (!empty($testoracle)) {
00298         $dsn = "oci8po://juris10:natsoft@sherkhan?persist";
00299         $db = ADONewConnection($dsn);
00300         print "<h1>Connecting $db->databaseType...</h1>";
00301         if (true || $db->Connect('', "scott", "natsoft",''))
00302                 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
00303         else print "ERROR: Oracle test requires an Oracle server setup with scott/natsoft".'<BR>'.$db->ErrorMsg();
00304 
00305 }
00306 ADOLoadCode("oracle"); // no longer supported
00307 if (false && !empty($testoracle)) { 
00308         
00309         $db = ADONewConnection();
00310         print "<h1>Connecting $db->databaseType...</h1>";
00311         if ($db->PConnect("", "scott", "tiger", "natsoft.domain"))
00312                 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
00313         else print "ERROR: Oracle test requires an Oracle server setup with scott/tiger".'<BR>'.$db->ErrorMsg();
00314 
00315 }
00316 
00317 ADOLoadCode("db2"); // no longer supported
00318 if (!empty($testdb2)) { 
00319         $db = ADONewConnection();
00320         print "<h1>Connecting $db->databaseType...</h1>";
00321         
00322         $dsn = "db2_sample";
00323         $dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP; uid=root; pwd=natsoft";
00324         if ($db->Connect($dsn)) {
00325         //      testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
00326         } else print "ERROR: DB2 test requires an server setup with odbc data source db2_sample".'<BR>'.$db->ErrorMsg();
00327 
00328 echo "<hr />";
00329 flush();
00330         $dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP; uid=root; pwd=natsoft";
00331         
00332         $db = ADONewConnection('odbtp');
00333         if ($db->Connect('127.0.0.1',$dsn)) {
00334                 
00335                 $db->debug=1;
00336                  $arr = $db->GetArray( "||SQLProcedures" ); adodb_pr($arr);
00337              $arr = $db->GetArray( "||SQLProcedureColumns|||GET_ROUTINE_SAR" );adodb_pr($arr);
00338         
00339                 testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
00340         } else echo ("ERROR Connection");
00341         echo $db->ErrorMsg();
00342 }
00343 
00344 
00345 $server = 'sherkhan';
00346 
00347 
00348 
00349 ADOLoadCode("mssqlpo");
00350 if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC
00351         $db = ADONewConnection("mssqlpo");
00352         //$db->debug=1;
00353         print "<h1>Connecting $db->databaseType...</h1>";
00354         
00355         $ok = $db->Connect('','adodb','natsoft','northwind');
00356 
00357         if ($ok or $db->PConnect("mangrove", "sa", "natsoft", "ai")) {
00358                 AutoDetect_MSSQL_Date_Order($db);
00359         //      $db->Execute('drop table adoxyz');
00360                 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
00361         } 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();
00362         
00363 }
00364 
00365 
00366 ADOLoadCode('odbc_mssql');
00367 if (!empty($testmssql)) { // MS SQL Server via ODBC
00368         $db = ADONewConnection();
00369         
00370         print "<h1>Connecting $db->databaseType...</h1>";
00371         
00372         $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;";
00373         
00374         if ($db->PConnect($dsn, "adodb", "natsoft", ""))  {
00375                 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
00376         }
00377         else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup";
00378 
00379 }
00380 
00381 ADOLoadCode("ado_mssql");
00382 if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less
00383         
00384         $db = &ADONewConnection("ado_mssql");
00385         //$db->debug=1;
00386         print "<h1>Connecting DSN-less $db->databaseType...</h1>";
00387         
00388         $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"
00389                 . "SERVER=$server;DATABASE=NorthWind;UID=adodb;PWD=natsoft;Trusted_Connection=No";
00390 
00391                 
00392         if ($db->PConnect($myDSN, "", "", ""))
00393                 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
00394         else print "ERROR: MSSQL test 2 requires MS SQL 7";
00395         
00396 }
00397 
00398 if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB provider
00399 
00400         $db = &ADONewConnection("ado_mssql");
00401         print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>";
00402         //$db->debug=1;
00403         $myDSN="SERVER=localhost;DATABASE=northwind;Trusted_Connection=yes";
00404         if ($db->PConnect($myDSN, "adodb", "natsoft", 'SQLOLEDB')) {
00405                 testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
00406         } else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='mangrove', userid='sa', password='', database='ai'";
00407 
00408 }
00409 
00410 
00411 if (extension_loaded('odbtp') && !empty($testmssql)) { // MS SQL Server via ODBC
00412         $db = ADONewConnection('odbtp');
00413         
00414         $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=$server;Database=northwind;uid=adodb;pwd=natsoft";
00415         
00416         if ($db->PConnect('localhost',$dsn, "", ""))  {
00417                 print "<h1>Connecting $db->databaseType...</h1>";                               
00418                 testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
00419         }
00420         else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup";
00421 
00422 }
00423 
00424 
00425 print "<h3>Tests Completed</h3>";
00426 
00427 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6