1--TEST-- 2PDO PgSQL Bug #62479 (PDO-psql cannot connect if password contains spaces) 3--EXTENSIONS-- 4pdo 5pdo_pgsql 6--SKIPIF-- 7<?php 8require __DIR__ . '/config.inc'; 9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 10PDOTest::skip(); 11 12$dsn = getenv('PDOTEST_DSN'); 13if (empty($dsn)) die('skip no dsn found in env'); 14 15$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 16$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 17 18 19$user = 'pdo_test62479'; 20$pass = 'testpass'; 21 22// Assume that if we can't create or drop a user, this test needs to be skipped 23try { 24 $db->exec("DROP USER IF EXISTS $user"); 25 $db->exec("CREATE USER $user WITH PASSWORD '$pass'"); 26} catch (PDOException $e) { 27 die("skip You need CREATEUSER permissions to run the test"); 28} 29 30// Peer authentication might prevent the test from properly running 31try { 32 $testConn = new PDO($dsn, $user, $pass); 33} catch (PDOException $e) { 34 echo "skip ".$e->getMessage(); 35} 36 37$db->exec("DROP USER $user"); 38 39?> 40--FILE-- 41<?php 42require __DIR__ . '/config.inc'; 43require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 44$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt'); 45$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); 46$user = "pdo_test62479"; 47$template = "CREATE USER $user WITH PASSWORD '%s'"; 48$testQuery = 'SELECT 1 as verification'; 49 50// Create temp user with space in password 51$sql = sprintf($template, 'my password'); 52$pdo->query($sql); 53$testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my password"); 54$result = $testConn->query($testQuery)->fetch(); 55$check = $result[0]; 56var_dump($check); 57 58// Remove the user 59$pdo->query("DROP USER $user"); 60 61// Create a user with a space and single quote 62$sql = sprintf($template, "my pass''word"); 63$pdo->query($sql); 64 65$testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my pass'word"); 66$result = $testConn->query($testQuery)->fetch(); 67$check = $result[0]; 68var_dump($check); 69?> 70--CLEAN-- 71<?php 72require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 73$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 74$db->exec("DROP USER pdo_test62479"); 75?> 76--EXPECT-- 77int(1) 78int(1) 79