home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / testdatabases.inc.php < prev    next >
Encoding:
PHP Script  |  2004-03-20  |  11.6 KB  |  286 lines

  1. <?php
  2.   
  3. /*
  4. V4.21 20 Mar 2004  (c) 2000-2004 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. <td><input type=checkbox name="testsqlite" value=1 <?php echo !empty($testsqlite) ? 'checked' : '' ?>> <b>SQLite</b><br>
  21. <input type=checkbox name="testproxy" value=1 <?php echo !empty($testproxy) ? 'checked' : '' ?>> <b>MySQL Proxy</b><br>
  22. <input type=checkbox name="testoracle" value=1 <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br>
  23. <input type=checkbox name="testpostgres" value=1 <?php echo !empty($testpostgres) ? 'checked' : '' ?>> <b>PostgreSQL</b><br>
  24. <input type=checkbox name="testpgodbc" value=1 <?php echo !empty($testpgodbc) ? 'checked' : '' ?>> <b>PostgreSQL ODBC</b><br>
  25. <td><input type=checkbox name="testdb2" value=1 <?php echo !empty($testdb2) ? 'checked' : '' ?>> DB2<br>
  26. <input type=checkbox name="testvfp" value=1 <?php echo !empty($testvfp) ? 'checked' : '' ?>> VFP<br>
  27. <input type=checkbox name="testado" value=1 <?php echo !empty($testado) ? 'checked' : '' ?>> ADO (for mssql and access)<br>
  28. <input type=checkbox name="nocountrecs" value=1 <?php echo !empty($nocountrecs) ? 'checked' : '' ?>> $ADODB_COUNTRECS=false<br>
  29. <input type=checkbox name="nolog" value=1 <?php echo !empty($nolog) ? 'checked' : '' ?>> No SQL Logging<br>
  30. <td><input type=submit>
  31. </form>
  32. </table>
  33. <?php
  34.  
  35. if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>";
  36.  
  37. if (isset($nocountrecs)) $ADODB_COUNTRECS = false;
  38.  
  39. // cannot test databases below, but we include them anyway to check
  40. // if they parse ok...
  41.  
  42. if (!strpos(PHP_VERSION,'5') === 0) {
  43.     ADOLoadCode("sybase");
  44.     ADOLoadCode("postgres");
  45.     ADOLoadCode("postgres7");
  46.     ADOLoadCode("firebird");
  47.     ADOLoadCode("borland_ibase");
  48.     ADOLoadCode("informix");
  49.     ADOLoadCode("sqlanywhere");
  50. }
  51.  
  52.  
  53. flush();
  54. if (!empty($testpostgres)) {
  55.     //ADOLoadCode("postgres");
  56.  
  57.     $db = &ADONewConnection('postgres');
  58.     print "<h1>Connecting $db->databaseType...</h1>";
  59.     if (@$db->Connect("localhost","tester","test","test")) {
  60.         testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)");
  61.     }else
  62.         print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg();
  63. }
  64.  
  65. if (!empty($testpgodbc)) { 
  66.     
  67.     $db = &ADONewConnection('odbc');
  68.     $db->hasTransactions = false;
  69.     print "<h1>Connecting $db->databaseType...</h1>";
  70.     
  71.     if ($db->PConnect('Postgresql')) {
  72.         $db->hasTransactions = true;
  73.         testdb($db,
  74.         "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
  75.     } else print "ERROR: PostgreSQL requires a database called test on server, user tester, password test.<BR>".$db->ErrorMsg();
  76. }
  77.  
  78. if (!empty($testibase)) {
  79.     
  80.     $db = &ADONewConnection('firebird');
  81.     print "<h1>Connecting $db->databaseType...</h1>";
  82.     if (@$db->PConnect("localhost:d:\\firebird\\10\\examples\\employee.gdb", "sysdba", "masterkey", ""))
  83.         testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),price numeric(12,2),created date)");
  84.      else print "ERROR: Interbase test requires a database called employee.gdb".'<BR>'.$db->ErrorMsg();
  85.     
  86. }
  87.  
  88.  
  89. if (!empty($testsqlite)) {
  90.     $db = &ADONewConnection('sqlite');
  91.     print "<h1>Connecting $db->databaseType...</h1>";
  92.     
  93.     if (@$db->PConnect("d:\\inetpub\\adodb\\sqlite.db", "", "", ""))
  94.         testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
  95.     else print "ERROR: SQLite";
  96.     
  97. }
  98.  
  99. // REQUIRES ODBC DSN CALLED nwind
  100. if (!empty($testaccess)) {
  101.     $db = &ADONewConnection('access');
  102.     print "<h1>Connecting $db->databaseType...</h1>";
  103.     
  104.     $dsn = "nwind";
  105.     $driver = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\inetpub\adodb\northwind.mdb;Uid=Admin;Pwd=;";
  106.     if (@$db->PConnect($dsn, "", "", ""))
  107.         testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
  108.     else print "ERROR: Access test requires a Windows ODBC DSN=nwind, Access driver";
  109.     
  110. }
  111.  
  112. if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS
  113.  
  114.     $db = &ADONewConnection("ado_access");
  115.     print "<h1>Connecting $db->databaseType...</h1>";
  116.     
  117.     $access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
  118.     $myDSN =  'PROVIDER=Microsoft.Jet.OLEDB.4.0;'
  119.         . 'DATA SOURCE=' . $access . ';';
  120.         //. 'USER ID=;PASSWORD=;';
  121.     
  122.     if (@$db->PConnect($myDSN, "", "", "")) {
  123.         print "ADO version=".$db->_connectionID->version."<br>";
  124.         testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
  125.     } else print "ERROR: Access test requires a Access database $access".'<BR>'.$db->ErrorMsg();
  126.     
  127. }
  128.  
  129. if (!empty($testvfp)) { // ODBC
  130.     $db = &ADONewConnection('vfp');
  131.     print "<h1>Connecting $db->databaseType...</h1>";flush();
  132.  
  133.     if ( $db->PConnect("vfp-adoxyz")) {
  134.         testdb($db,"create table d:\\inetpub\\adodb\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");
  135.      } else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=vfp-adoxyz, VFP driver";
  136.     
  137. }
  138.  
  139.  
  140. // REQUIRES MySQL server at localhost with database 'test'
  141. if (!empty($testmysql)) { // MYSQL
  142.  
  143.     $db = &ADONewConnection('mysql');
  144.     print "<h1>Connecting $db->databaseType...</h1>";
  145.     if (PHP_VERSION >= 5 || $HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';
  146.     else $server = "mangrove";
  147.     if ($db->PConnect($server, "root", "", "northwind")) {
  148.         //$db->debug=1;$db->Execute('drop table ADOXYZ');
  149.         testdb($db,
  150.         "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)");
  151.     } else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
  152. }
  153.  
  154. // REQUIRES MySQL server at localhost with database 'test'
  155. if (!empty($testmysqlodbc)) { // MYSQL
  156.     
  157.     $db = &ADONewConnection('odbc');
  158.     $db->hasTransactions = false;
  159.     print "<h1>Connecting $db->databaseType...</h1>";
  160.     if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';
  161.     else $server = "mangrove";
  162.     if ($db->PConnect('mysql', "root", ""))
  163.         testdb($db,
  164.         "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
  165.     else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
  166. }
  167.  
  168. if (!empty($testproxy)){
  169.     $db = &ADONewConnection('proxy');
  170.     print "<h1>Connecting $db->databaseType...</h1>";
  171.     if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';
  172.  
  173.     if ($db->PConnect('http://localhost/php/phplens/adodb/server.php'))
  174.         testdb($db,
  175.         "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
  176.     else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
  177.  
  178. }
  179.  
  180. ADOLoadCode('oci805');
  181. ADOLoadCode("oci8po");
  182. if (!empty($testoracle)) { 
  183.     
  184.     $db = ADONewConnection('oci8po');
  185.     print "<h1>Connecting $db->databaseType...</h1>";
  186.     if ($db->Connect('', "scott", "natsoft",''))
  187.     //if ($db->PConnect("", "scott", "tiger", "juris.ecosystem.natsoft.com.my"))
  188.         testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
  189.     else print "ERROR: Oracle test requires an Oracle server setup with scott/natsoft".'<BR>'.$db->ErrorMsg();
  190.  
  191. }
  192. ADOLoadCode("oracle"); // no longer supported
  193. if (false && !empty($testoracle)) { 
  194.     
  195.     $db = ADONewConnection();
  196.     print "<h1>Connecting $db->databaseType...</h1>";
  197.     if ($db->PConnect("", "scott", "tiger", "natsoft.domain"))
  198.         testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
  199.     else print "ERROR: Oracle test requires an Oracle server setup with scott/tiger".'<BR>'.$db->ErrorMsg();
  200.  
  201. }
  202.  
  203. ADOLoadCode("db2"); // no longer supported
  204. if (!empty($testdb2)) { 
  205.     
  206.     $db = ADONewConnection();
  207.     print "<h1>Connecting $db->databaseType...</h1>";
  208.     if ($db->Connect("db2_sample", "root", "natsoft", ""))
  209.         testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
  210.     else print "ERROR: DB2 test requires an server setup with odbc data source db2_sample".'<BR>'.$db->ErrorMsg();
  211.  
  212. }
  213.  
  214.  
  215. ADOLoadCode('odbc_mssql');
  216. if (!empty($testmssql)) { // MS SQL Server via ODBC
  217.     $db = ADONewConnection();
  218.     
  219.     print "<h1>Connecting $db->databaseType...</h1>";
  220.     
  221.     $dsn = "mssql-northwind";
  222.     $dsn = "Driver={SQL Server};Server=localhost;Database=northwind;";
  223.     
  224.     if (@$db->PConnect($dsn, "adodb", "natsoft", ""))  {
  225.         testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
  226.     }
  227.     else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN setup";
  228.  
  229. }
  230.  
  231. ADOLoadCode("ado_mssql");
  232.  
  233. if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less
  234.     
  235.     $db = &ADONewConnection("ado_mssql");
  236.     //$db->debug=1;
  237.     print "<h1>Connecting DSN-less $db->databaseType...</h1>";
  238.     
  239.     $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"
  240.         . "SERVER=tigress;DATABASE=NorthWind;UID=adodb;PWD=natsoft;Trusted_Connection=No"  ;
  241.  
  242.         
  243.     if (@$db->PConnect($myDSN, "", "", ""))
  244.         testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
  245.     else print "ERROR: MSSQL test 2 requires MS SQL 7";
  246.     
  247. }
  248.  
  249.  
  250. ADOLoadCode("mssqlpo");
  251. if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC
  252.     $db = ADONewConnection("mssqlpo");
  253.     //$db->debug=1;
  254.     print "<h1>Connecting $db->databaseType...</h1>";
  255.     
  256.     $ok = $db->PConnect('tigress','adodb','natsoft','northwind');
  257.     //$rs = $db->Execute("exec sp_ddate");
  258.     //print_r($rs->fields);
  259.     //die();
  260.  
  261.     if ($ok or @$db->PConnect("mangrove", "sa", "natsoft", "ai")) {
  262.         AutoDetect_MSSQL_Date_Order($db);
  263.     //    $db->Execute('drop table adoxyz');
  264.         testdb($db,"create table ADOXYZ (id int, firstname char(24) null, lastname char(24) null,created datetime null)");
  265.     } else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='192.168.0.1', userid='sa', password='natsoft', database='ai'".'<BR>'.$db->ErrorMsg();
  266.     
  267. }
  268.  
  269. if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB provider
  270.  
  271.     $db = &ADONewConnection("ado_mssql");
  272.     print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>";
  273.     //$db->debug=1;
  274.     $myDSN="SERVER=tigress;DATABASE=northwind;Trusted_Connection=yes";
  275.     //$myDSN='SERVER=(local)\NetSDK;DATABASE=northwind;';
  276.     if ($db->PConnect($myDSN, "adodb", "natsoft", 'SQLOLEDB'))
  277.         testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
  278.     else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='mangrove', userid='sa', password='', database='ai'";
  279.  
  280. }
  281.  
  282.  
  283. print "<h3>Tests Completed</h3>";
  284.  
  285. ?>
  286.