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