1--TEST-- 2MySQL PDO->__construct() - URI 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die('skip only for Windows'); 7} 8require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); 9require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 10MySQLPDOTest::skip(); 11?> 12--FILE-- 13<?php 14 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 15 16 try { 17 18 if ($tmp = MySQLPDOTest::getTempDir()) { 19 20 $file = $tmp . DIRECTORY_SEPARATOR . 'pdomuri.tst'; 21 $dsn = MySQLPDOTest::getDSN(); 22 $user = PDO_MYSQL_TEST_USER; 23 $pass = PDO_MYSQL_TEST_PASS; 24 $uri = sprintf('uri:file:%s', $file); 25 26 if ($fp = @fopen($file, 'w')) { 27 // ok, great we can create a file with a DSN in it 28 fwrite($fp, $dsn); 29 fclose($fp); 30 clearstatcache(); 31 assert(file_exists($file)); 32 try { 33 $db = new PDO($uri, $user, $pass); 34 } catch (PDOException $e) { 35 printf("[002] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n", 36 $uri, $dsn, 37 $file, filesize($file), file_get_contents($file), 38 $e->getMessage()); 39 } 40 unlink($file); 41 } 42 43 if ($fp = @fopen($file, 'w')) { 44 fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s', 45 chr(0), $dsn)); 46 fclose($fp); 47 clearstatcache(); 48 assert(file_exists($file)); 49 try { 50 $db = new PDO($uri, $user, $pass); 51 } catch (PDOException $e) { 52 printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n", 53 $uri, $dsn, 54 $file, filesize($file), file_get_contents($file), 55 $e->getMessage()); 56 } 57 unlink($file); 58 } 59 60 } 61 62 /* TODO: safe mode */ 63 64 } catch (PDOException $e) { 65 printf("[001] %s, [%s] %s\n", 66 $e->getMessage(), 67 (is_object($db)) ? $db->errorCode() : 'n/a', 68 (is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a'); 69 } 70 71 print "done!"; 72?> 73--EXPECTF-- 74Warning: PDO::__construct(file:%spdomuri.tst): failed to open stream: Invalid argument in %s on line %d 75[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI 76 77Warning: PDO::__construct(file:%spdomuri.tst): failed to open stream: Invalid argument in %s on line %d 78[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 79done! 80