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