1--TEST--
2MySQL PDO->__construct() - URI
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13
14    try {
15
16        if ($tmp = MySQLPDOTest::getTempDir()) {
17            $file = $tmp . DIRECTORY_SEPARATOR . 'pdomuri.tst';
18            $dsn = MySQLPDOTest::getDSN();
19            $user = PDO_MYSQL_TEST_USER;
20            $pass = PDO_MYSQL_TEST_PASS;
21            $uri = 'uri:file://' . $file;
22
23            if ($fp = @fopen($file, 'w')) {
24                fwrite($fp, $dsn);
25                fclose($fp);
26                clearstatcache();
27                assert(file_exists($file));
28                try {
29                    $db = new PDO($uri, $user, $pass);
30                } catch (PDOException $e) {
31                    printf("[002] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
32                        $uri, $dsn,
33                        $file, filesize($file), file_get_contents($file),
34                        $e->getMessage());
35                }
36                unlink($file);
37            }
38
39            if ($fp = @fopen($file, 'w')) {
40                fwrite($fp, $dsn . chr(0) . ';host=nonsense;unix_socket=nonsense');
41                fclose($fp);
42                clearstatcache();
43                assert(file_exists($file));
44                try {
45                    $db = new PDO($uri, $user, $pass);
46                } catch (PDOException $e) {
47                    printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
48                        $uri, $dsn,
49                        $file, filesize($file), file_get_contents($file),
50                        $e->getMessage());
51                }
52                unlink($file);
53            }
54
55        }
56
57    } catch (PDOException $e) {
58        printf("[001] %s, [%s] %s\n",
59            $e->getMessage(),
60            (is_object($db)) ? $db->errorCode() : 'n/a',
61            (is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
62    }
63
64    print "done!";
65?>
66--EXPECT--
67done!
68