1--TEST--
2MySQL PDO->__construct() - URI
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8?>
9--FILE--
10<?php
11	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
12
13	try {
14
15		if ($tmp = MySQLPDOTest::getTempDir()) {
16
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 = sprintf('uri:file:%s', $file);
22
23			if ($fp = @fopen($file, 'w')) {
24				// ok, great we can create a file with a DSN in it
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, sprintf('mysql:dbname=letshopeinvalid;%s%s',
42					chr(0), $dsn));
43				fclose($fp);
44				clearstatcache();
45				assert(file_exists($file));
46				try {
47					$db = new PDO($uri, $user, $pass);
48				} catch (PDOException $e) {
49					printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n",
50					$uri, $dsn,
51					$file, filesize($file), file_get_contents($file),
52					$e->getMessage());
53				}
54				unlink($file);
55			}
56
57		}
58
59		/* TODO: safe mode */
60
61	} catch (PDOException $e) {
62		printf("[001] %s, [%s] %s\n",
63			$e->getMessage(),
64			(is_object($db)) ? $db->errorCode() : 'n/a',
65			(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
66	}
67
68	print "done!";
69?>
70--EXPECTF--
71Warning: PDO::__construct(%s
72[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI
73
74Warning: PDO::__construct(%s
75[003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
76done!
77