1--TEST--
2Basic test for connection. (When not using a DSN alias)
3--EXTENSIONS--
4pdo_odbc
5--SKIPIF--
6<?php
7require 'ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9$dsn = getenv('PDO_ODBC_TEST_DSN');
10if (!$dsn || strpos($dsn, '=') === false) {
11    die('skip');
12}
13?>
14--XLEAK--
15A bug in msodbcsql causes a memory leak when reconnecting after closing. See GH-12306
16--FILE--
17<?php
18$dsnWithCredentials = getenv('PDO_ODBC_TEST_DSN');
19$user = getenv('PDO_ODBC_TEST_USER');
20$password = getenv('PDO_ODBC_TEST_PASS');
21
22$dsn = str_replace(";uid={$user};pwd={$password}", '', $dsnWithCredentials);
23
24echo "dsn without credentials / correct user / correct password\n";
25try {
26    $db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
27    echo "Connected.\n\n";
28    $db = null;
29} catch (PDOException $e) {
30    echo $e->getMessage()."\n";
31}
32
33echo "dsn with credentials / no user / no password\n";
34try {
35    $db = new PDO("{$dsn};uid={$user};pwd={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
36    echo "Connected.\n\n";
37    $db = null;
38} catch (PDOException $e) {
39    echo $e->getMessage()."\n";
40}
41
42echo "dsn with correct user / incorrect user / correct password\n";
43try {
44    $db = new PDO("{$dsn};UID={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
45    echo "Connected.\n\n";
46    $db = null;
47} catch (PDOException $e) {
48    echo $e->getMessage()."\n";
49}
50
51echo "dsn with correct password / correct user / incorrect password\n";
52try {
53    $db = new PDO("{$dsn};PWD={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
54    echo "Connected.\n\n";
55    $db = null;
56} catch (PDOException $e) {
57    echo $e->getMessage()."\n";
58}
59
60echo "dsn with correct credentials / incorrect user / incorrect password\n";
61try {
62    $db = new PDO("{$dsn};Uid={$user};Pwd={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
63    echo "Connected.\n";
64    $db = null;
65} catch (PDOException $e) {
66    echo $e->getMessage()."\n";
67}
68?>
69--EXPECT--
70dsn without credentials / correct user / correct password
71Connected.
72
73dsn with credentials / no user / no password
74Connected.
75
76dsn with correct user / incorrect user / correct password
77Connected.
78
79dsn with correct password / correct user / incorrect password
80Connected.
81
82dsn with correct credentials / incorrect user / incorrect password
83Connected.
84