xref: /php-src/ext/pdo_mysql/tests/bug_50323.phpt (revision 4bb75d56)
1--TEST--
2Bug #50323 (No ability to connect to database named 't;', no chance to escape semicolon)
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    $db = MySQLPDOTest::factory();
14
15    function changeDSN($original, $new_options) {
16        $old_options = array();
17        $dsn = substr($original,
18                strpos($original, ':') + 1,
19                strlen($original));
20
21        // no real parser - any exotic setting can fool us
22        $parts = explode(';', $dsn);
23        foreach ($parts as $k => $v) {
24            $tmp = explode('=', $v);
25            if (count($tmp) == 2)
26                    $old_options[$tmp[0]] = $tmp[1];
27        }
28
29        $options = $old_options;
30        foreach ($new_options as $k => $v)
31            $options[$k] = $v;
32
33        $dsn = 'mysql:';
34        foreach ($options as $k => $v)
35            $dsn .= sprintf('%s=%s;', $k, $v);
36
37        $dsn = substr($dsn, 0, strlen($dsn) -1);
38
39        return $dsn;
40    }
41
42
43    if (1 === @$db->exec('CREATE DATABASE `crazy;dbname`')) {
44        $dsn = changeDSN(PDO_MYSQL_TEST_DSN, array('dbname' => 'crazy;;dbname'));
45        $user = PDO_MYSQL_TEST_USER;
46        $pass = PDO_MYSQL_TEST_PASS;
47
48        new PDO($dsn, $user, $pass);
49    }
50    echo 'done!';
51?>
52--CLEAN--
53<?php
54require_once __DIR__ . '/inc/mysql_pdo_test.inc';
55$db = MySQLPDOTest::factory();
56
57$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
58?>
59--EXPECT--
60done!
61