common.phpt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --TEST--
  2. ODBC
  3. --SKIPIF--
  4. <?php # vim:ft=php
  5. if (!extension_loaded('pdo_odbc')) print 'skip';
  6. if (substr(PHP_OS, 0, 3) == 'WIN' &&
  7. false === getenv('PDOTEST_DSN') &&
  8. false === getenv('PDO_ODBC_TEST_DSN') &&
  9. !extension_loaded('com_dotnet')) {
  10. die('skip - either PDOTEST_DSN or com_dotnet extension is needed to setup the connection');
  11. }
  12. --REDIRECTTEST--
  13. # magic auto-configuration
  14. $config = array(
  15. 'TESTS' => 'ext/pdo/tests',
  16. 'ENV' => array()
  17. );
  18. // try loading PDO driver using ENV vars and if none given, and on Windows, try using MS Access
  19. // and if not, skip the test
  20. //
  21. // try to use common PDO env vars, instead of PDO_ODBC specific
  22. if (false !== getenv('PDOTEST_DSN')) {
  23. // user should have to set PDOTEST_DSN so that:
  24. // 1. test is skipped if user doesn't want to test it, even if they have MS Access installed
  25. // 2. it detects if ODBC driver is not installed - to avoid test bug
  26. // 3. it detects if ODBC driver is installed - so test will be run
  27. // 4. so a specific ODBC driver can be tested - if system has multiple ODBC drivers
  28. $config['ENV']['PDOTEST_DSN'] = getenv('PDOTEST_DSN');
  29. $config['ENV']['PDOTEST_USER'] = getenv('PDOTEST_USER');
  30. $config['ENV']['PDOTEST_PASS'] = getenv('PDOTEST_PASS');
  31. if (false !== getenv('PDOTEST_ATTR')) {
  32. $config['ENV']['PDOTEST_ATTR'] = getenv('PDOTEST_ATTR');
  33. }
  34. } else if (false !== getenv('PDO_ODBC_TEST_DSN')) {
  35. // user set these from their shell instead
  36. $config['ENV']['PDOTEST_DSN'] = getenv('PDO_ODBC_TEST_DSN');
  37. $config['ENV']['PDOTEST_USER'] = getenv('PDO_ODBC_TEST_USER');
  38. $config['ENV']['PDOTEST_PASS'] = getenv('PDO_ODBC_TEST_PASS');
  39. if (false !== getenv('PDO_ODBC_TEST_ATTR')) {
  40. $config['ENV']['PDOTEST_ATTR'] = getenv('PDO_ODBC_TEST_ATTR');
  41. }
  42. } elseif (preg_match('/^WIN/i', PHP_OS)) {
  43. // on Windows and user didn't set PDOTEST_DSN, try this as a fallback:
  44. // check if MS Access DB is installed, and if yes, try using it. create a temporary MS access database.
  45. //
  46. $path = realpath(dirname(__FILE__)) . '\pdo_odbc.mdb';
  47. if (!file_exists($path)) {
  48. try {
  49. // try to create database
  50. $adox = new COM('ADOX.Catalog');
  51. $adox->Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' . $path);
  52. $adox = null;
  53. } catch (Exception $e) {
  54. }
  55. }
  56. if (file_exists($path)) {
  57. // database was created and written to file system
  58. $config['ENV']['PDOTEST_DSN'] = "odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$path;Uid=Admin";
  59. } // else: $config['ENV']['PDOTEST_DSN'] not set
  60. } // else: $config['ENV']['PDOTEST_DSN'] not set
  61. // test will be skipped. see SKIPIF section of long_columns.phpt
  62. # other magic autodetection here, eg: for DB2 by inspecting env
  63. /*
  64. $USER = 'db2inst1';
  65. $PASSWD = 'ibmdb2';
  66. $DBNAME = 'SAMPLE';
  67. $CONNECTION = "odbc:DSN=$DBNAME;UID=$USER;PWD=$PASSWD;";
  68. */
  69. return $config;