xref: /PHP-8.2/ext/pdo_mysql/tests/bug_50323.phpt (revision 39131219)
1--TEST--
2Bug #50323 (No ability to connect to database named 't;', no chance to escape semicolon)
3--EXTENSIONS--
4pdo
5pdo_mysql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16
17    function changeDSN($original, $new_options) {
18        $old_options = array();
19        $dsn = substr($original,
20                strpos($original, ':') + 1,
21                strlen($original));
22
23        // no real parser - any exotic setting can fool us
24        $parts = explode(';', $dsn);
25        foreach ($parts as $k => $v) {
26            $tmp = explode('=', $v);
27            if (count($tmp) == 2)
28                    $old_options[$tmp[0]] = $tmp[1];
29        }
30
31        $options = $old_options;
32        foreach ($new_options as $k => $v)
33            $options[$k] = $v;
34
35        $dsn = 'mysql:';
36        foreach ($options as $k => $v)
37            $dsn .= sprintf('%s=%s;', $k, $v);
38
39        $dsn = substr($dsn, 0, strlen($dsn) -1);
40
41        return $dsn;
42    }
43
44
45if (1 === @$db->exec('CREATE DATABASE `crazy;dbname`')) {
46    $dsn = changeDSN(getenv('PDOTEST_DSN'), array('dbname' => 'crazy;;dbname'));
47    $user = getenv('PDOTEST_USER');
48    $pass = getenv('PDOTEST_PASS');
49
50    new PDO($dsn, $user, $pass);
51}
52echo 'done!';
53?>
54--CLEAN--
55<?php
56require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
57$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
58
59@$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
60?>
61--EXPECT--
62done!
63