common.phpt 2.7 KB

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