home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / db_parsedsn.phpt < prev    next >
Encoding:
Text File  |  2004-03-24  |  9.6 KB  |  481 lines

  1. --TEST--
  2. DB::parseDSN
  3. --SKIPIF--
  4. <?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
  5. --FILE--
  6. <?php // -*- C++ -*-
  7. require_once './include.inc';
  8. require_once 'DB.php';
  9.  
  10. function test($dsn) {
  11.     echo "DSN: $dsn\n";
  12.     print_r(DB::parseDSN($dsn));
  13. }
  14.  
  15. function testArray($dsn) {
  16.     echo "DSN: array\n";
  17.     print_r(DB::parseDSN($dsn));
  18. }
  19.  
  20. print "testing DB::parseDSN...\n\n";
  21.  
  22. test("mysql");
  23. test("odbc(mssql)");
  24. test('odbc(db2)://user:password@/database');
  25. test('odbc(access):///database');
  26. test('odbc://admin@/datasourceName');
  27. test("mysql://localhost");
  28. test("mysql://remote.host.com/db");
  29. test("oci8://system:manager@");
  30. test("oci8://user:pass@tns-name");
  31. test("odbc(solid)://foo:bar@tcp+localhost+1313");  // deprecated
  32. test("pgsql://user@unix+localhost/pear");          // deprecated
  33. test("ibase://user%40domain:password@host");
  34. test("ibase://user@domain:pass@word@/database");   // also supported
  35. test("ifx://user@domain:pass@word@host.com//usr/db/general.db");
  36. test('ifx://remote.host.com/c:\windows\my.db');
  37. test('oci8://SHOOTOUT:******@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.101.161)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=TIS)))');
  38.  
  39. // new formats
  40. test("odbc(solid)://foo:bar@localhost:1313");
  41. test("pgsql://user@unix()/pear");
  42. test("mysql://user@unix(/path/to/socket)/pear");
  43. test("pgsql://user@tcp()/pear");
  44. test("pgsql://user@tcp(somehost)/pear");
  45. test("pgsql://user:pass@word@tcp(somehost:7777)/pear");
  46.  
  47. // special backend options
  48. test('ibase://user:pass@localhost//var/lib/dbase.dbf?role=foo');
  49. test('dbase://@/?role=foo&dialect=bar');
  50. test('sqlite:////unix/path/to/database?option=value&anotheroption=anothervalue');
  51. test('sqlite:///c:/win/path/to/database?option=value');
  52.  
  53. // some examples from manual
  54. test('mysql://username@hostspec');
  55. test('mysql://hostspec/database');
  56. test('mysql://hostspec');
  57. test('mysql:///database');
  58.  
  59. // array tests
  60. $array = array(
  61.     'phptype'  => 'mysql',
  62.     'hostspec' => 'foobar',
  63. );
  64. testArray($array);
  65.  
  66. ?>
  67. --GET--
  68. --POST--
  69. --EXPECT--
  70. testing DB::parseDSN...
  71.  
  72. DSN: mysql
  73. Array
  74. (
  75.     [phptype] => mysql
  76.     [dbsyntax] => mysql
  77.     [username] => 
  78.     [password] => 
  79.     [protocol] => 
  80.     [hostspec] => 
  81.     [port] => 
  82.     [socket] => 
  83.     [database] => 
  84. )
  85. DSN: odbc(mssql)
  86. Array
  87. (
  88.     [phptype] => odbc
  89.     [dbsyntax] => mssql
  90.     [username] => 
  91.     [password] => 
  92.     [protocol] => 
  93.     [hostspec] => 
  94.     [port] => 
  95.     [socket] => 
  96.     [database] => 
  97. )
  98. DSN: odbc(db2)://user:password@/database
  99. Array
  100. (
  101.     [phptype] => odbc
  102.     [dbsyntax] => db2
  103.     [username] => user
  104.     [password] => password
  105.     [protocol] => tcp
  106.     [hostspec] => 
  107.     [port] => 
  108.     [socket] => 
  109.     [database] => database
  110. )
  111. DSN: odbc(access):///database
  112. Array
  113. (
  114.     [phptype] => odbc
  115.     [dbsyntax] => access
  116.     [username] => 
  117.     [password] => 
  118.     [protocol] => tcp
  119.     [hostspec] => 
  120.     [port] => 
  121.     [socket] => 
  122.     [database] => database
  123. )
  124. DSN: odbc://admin@/datasourceName
  125. Array
  126. (
  127.     [phptype] => odbc
  128.     [dbsyntax] => odbc
  129.     [username] => admin
  130.     [password] => 
  131.     [protocol] => tcp
  132.     [hostspec] => 
  133.     [port] => 
  134.     [socket] => 
  135.     [database] => datasourceName
  136. )
  137. DSN: mysql://localhost
  138. Array
  139. (
  140.     [phptype] => mysql
  141.     [dbsyntax] => mysql
  142.     [username] => 
  143.     [password] => 
  144.     [protocol] => tcp
  145.     [hostspec] => localhost
  146.     [port] => 
  147.     [socket] => 
  148.     [database] => 
  149. )
  150. DSN: mysql://remote.host.com/db
  151. Array
  152. (
  153.     [phptype] => mysql
  154.     [dbsyntax] => mysql
  155.     [username] => 
  156.     [password] => 
  157.     [protocol] => tcp
  158.     [hostspec] => remote.host.com
  159.     [port] => 
  160.     [socket] => 
  161.     [database] => db
  162. )
  163. DSN: oci8://system:manager@
  164. Array
  165. (
  166.     [phptype] => oci8
  167.     [dbsyntax] => oci8
  168.     [username] => system
  169.     [password] => manager
  170.     [protocol] => tcp
  171.     [hostspec] => 
  172.     [port] => 
  173.     [socket] => 
  174.     [database] => 
  175. )
  176. DSN: oci8://user:pass@tns-name
  177. Array
  178. (
  179.     [phptype] => oci8
  180.     [dbsyntax] => oci8
  181.     [username] => user
  182.     [password] => pass
  183.     [protocol] => tcp
  184.     [hostspec] => tns-name
  185.     [port] => 
  186.     [socket] => 
  187.     [database] => 
  188. )
  189. DSN: odbc(solid)://foo:bar@tcp+localhost+1313
  190. Array
  191. (
  192.     [phptype] => odbc
  193.     [dbsyntax] => solid
  194.     [username] => foo
  195.     [password] => bar
  196.     [protocol] => tcp
  197.     [hostspec] => localhost+1313
  198.     [port] => 
  199.     [socket] => 
  200.     [database] => 
  201. )
  202. DSN: pgsql://user@unix+localhost/pear
  203. Array
  204. (
  205.     [phptype] => pgsql
  206.     [dbsyntax] => pgsql
  207.     [username] => user
  208.     [password] => 
  209.     [protocol] => unix
  210.     [hostspec] => 
  211.     [port] => 
  212.     [socket] => localhost
  213.     [database] => pear
  214. )
  215. DSN: ibase://user%40domain:password@host
  216. Array
  217. (
  218.     [phptype] => ibase
  219.     [dbsyntax] => ibase
  220.     [username] => user@domain
  221.     [password] => password
  222.     [protocol] => tcp
  223.     [hostspec] => host
  224.     [port] => 
  225.     [socket] => 
  226.     [database] => 
  227. )
  228. DSN: ibase://user@domain:pass@word@/database
  229. Array
  230. (
  231.     [phptype] => ibase
  232.     [dbsyntax] => ibase
  233.     [username] => user@domain
  234.     [password] => pass@word
  235.     [protocol] => tcp
  236.     [hostspec] => 
  237.     [port] => 
  238.     [socket] => 
  239.     [database] => database
  240. )
  241. DSN: ifx://user@domain:pass@word@host.com//usr/db/general.db
  242. Array
  243. (
  244.     [phptype] => ifx
  245.     [dbsyntax] => ifx
  246.     [username] => user@domain
  247.     [password] => pass@word
  248.     [protocol] => tcp
  249.     [hostspec] => host.com
  250.     [port] => 
  251.     [socket] => 
  252.     [database] => /usr/db/general.db
  253. )
  254. DSN: ifx://remote.host.com/c:\windows\my.db
  255. Array
  256. (
  257.     [phptype] => ifx
  258.     [dbsyntax] => ifx
  259.     [username] => 
  260.     [password] => 
  261.     [protocol] => tcp
  262.     [hostspec] => remote.host.com
  263.     [port] => 
  264.     [socket] => 
  265.     [database] => c:\windows\my.db
  266. )
  267. DSN: oci8://SHOOTOUT:******@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.101.161)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=TIS)))
  268. Array
  269. (
  270.     [phptype] => oci8
  271.     [dbsyntax] => oci8
  272.     [username] => SHOOTOUT
  273.     [password] => ******
  274.     [protocol] => tcp
  275.     [hostspec] => (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.101.161)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=TIS)))
  276.     [port] => 
  277.     [socket] => 
  278.     [database] => 
  279. )
  280. DSN: odbc(solid)://foo:bar@localhost:1313
  281. Array
  282. (
  283.     [phptype] => odbc
  284.     [dbsyntax] => solid
  285.     [username] => foo
  286.     [password] => bar
  287.     [protocol] => tcp
  288.     [hostspec] => localhost
  289.     [port] => 1313
  290.     [socket] => 
  291.     [database] => 
  292. )
  293. DSN: pgsql://user@unix()/pear
  294. Array
  295. (
  296.     [phptype] => pgsql
  297.     [dbsyntax] => pgsql
  298.     [username] => user
  299.     [password] => 
  300.     [protocol] => unix
  301.     [hostspec] => 
  302.     [port] => 
  303.     [socket] => 
  304.     [database] => pear
  305. )
  306. DSN: mysql://user@unix(/path/to/socket)/pear
  307. Array
  308. (
  309.     [phptype] => mysql
  310.     [dbsyntax] => mysql
  311.     [username] => user
  312.     [password] => 
  313.     [protocol] => unix
  314.     [hostspec] => 
  315.     [port] => 
  316.     [socket] => /path/to/socket
  317.     [database] => pear
  318. )
  319. DSN: pgsql://user@tcp()/pear
  320. Array
  321. (
  322.     [phptype] => pgsql
  323.     [dbsyntax] => pgsql
  324.     [username] => user
  325.     [password] => 
  326.     [protocol] => tcp
  327.     [hostspec] => 
  328.     [port] => 
  329.     [socket] => 
  330.     [database] => pear
  331. )
  332. DSN: pgsql://user@tcp(somehost)/pear
  333. Array
  334. (
  335.     [phptype] => pgsql
  336.     [dbsyntax] => pgsql
  337.     [username] => user
  338.     [password] => 
  339.     [protocol] => tcp
  340.     [hostspec] => somehost
  341.     [port] => 
  342.     [socket] => 
  343.     [database] => pear
  344. )
  345. DSN: pgsql://user:pass@word@tcp(somehost:7777)/pear
  346. Array
  347. (
  348.     [phptype] => pgsql
  349.     [dbsyntax] => pgsql
  350.     [username] => user
  351.     [password] => pass@word
  352.     [protocol] => tcp
  353.     [hostspec] => somehost
  354.     [port] => 7777
  355.     [socket] => 
  356.     [database] => pear
  357. )
  358. DSN: ibase://user:pass@localhost//var/lib/dbase.dbf?role=foo
  359. Array
  360. (
  361.     [phptype] => ibase
  362.     [dbsyntax] => ibase
  363.     [username] => user
  364.     [password] => pass
  365.     [protocol] => tcp
  366.     [hostspec] => localhost
  367.     [port] => 
  368.     [socket] => 
  369.     [database] => /var/lib/dbase.dbf
  370.     [role] => foo
  371. )
  372. DSN: dbase://@/?role=foo&dialect=bar
  373. Array
  374. (
  375.     [phptype] => dbase
  376.     [dbsyntax] => dbase
  377.     [username] => 
  378.     [password] => 
  379.     [protocol] => tcp
  380.     [hostspec] => 
  381.     [port] => 
  382.     [socket] => 
  383.     [database] => 
  384.     [role] => foo
  385.     [dialect] => bar
  386. )
  387. DSN: sqlite:////unix/path/to/database?option=value&anotheroption=anothervalue
  388. Array
  389. (
  390.     [phptype] => sqlite
  391.     [dbsyntax] => sqlite
  392.     [username] => 
  393.     [password] => 
  394.     [protocol] => tcp
  395.     [hostspec] => 
  396.     [port] => 
  397.     [socket] => 
  398.     [database] => /unix/path/to/database
  399.     [option] => value
  400.     [anotheroption] => anothervalue
  401. )
  402. DSN: sqlite:///c:/win/path/to/database?option=value
  403. Array
  404. (
  405.     [phptype] => sqlite
  406.     [dbsyntax] => sqlite
  407.     [username] => 
  408.     [password] => 
  409.     [protocol] => tcp
  410.     [hostspec] => 
  411.     [port] => 
  412.     [socket] => 
  413.     [database] => c:/win/path/to/database
  414.     [option] => value
  415. )
  416. DSN: mysql://username@hostspec
  417. Array
  418. (
  419.     [phptype] => mysql
  420.     [dbsyntax] => mysql
  421.     [username] => username
  422.     [password] => 
  423.     [protocol] => tcp
  424.     [hostspec] => hostspec
  425.     [port] => 
  426.     [socket] => 
  427.     [database] => 
  428. )
  429. DSN: mysql://hostspec/database
  430. Array
  431. (
  432.     [phptype] => mysql
  433.     [dbsyntax] => mysql
  434.     [username] => 
  435.     [password] => 
  436.     [protocol] => tcp
  437.     [hostspec] => hostspec
  438.     [port] => 
  439.     [socket] => 
  440.     [database] => database
  441. )
  442. DSN: mysql://hostspec
  443. Array
  444. (
  445.     [phptype] => mysql
  446.     [dbsyntax] => mysql
  447.     [username] => 
  448.     [password] => 
  449.     [protocol] => tcp
  450.     [hostspec] => hostspec
  451.     [port] => 
  452.     [socket] => 
  453.     [database] => 
  454. )
  455. DSN: mysql:///database
  456. Array
  457. (
  458.     [phptype] => mysql
  459.     [dbsyntax] => mysql
  460.     [username] => 
  461.     [password] => 
  462.     [protocol] => tcp
  463.     [hostspec] => 
  464.     [port] => 
  465.     [socket] => 
  466.     [database] => database
  467. )
  468. DSN: array
  469. Array
  470. (
  471.     [phptype] => mysql
  472.     [dbsyntax] => mysql
  473.     [username] => 
  474.     [password] => 
  475.     [protocol] => 
  476.     [hostspec] => foobar
  477.     [port] => 
  478.     [socket] => 
  479.     [database] => 
  480. )
  481.