PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/include/adodb/tests/testdatabases.inc.php

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