home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / testdatabases.inc.php < prev    next >
Encoding:
PHP Script  |  2005-01-24  |  14.3 KB  |  343 lines

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