xref: /PHP-7.2/ext/pdo/tests/pdo_033.phpt (revision d7cc1ce5)
1--TEST--
2PDO Common: PDO::quote()
3--SKIPIF--
4<?php # vim:ft=php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8if (!strncasecmp(getenv('PDOTEST_DSN'), 'odbc', strlen('odbc'))) die('skip odbc driver doesn\'t have escape API, use prepared statements');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$unquoted = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
19
20$quoted = $db->quote($unquoted);
21
22$len = strlen($unquoted);
23
24@$db->exec("DROP TABLE test");
25
26$db->query("CREATE TABLE test (t char($len))");
27$db->query("INSERT INTO test (t) VALUES($quoted)");
28
29$stmt = $db->prepare('SELECT * from test');
30$stmt->execute();
31
32print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
33
34$db->exec("DROP TABLE test");
35
36?>
37--EXPECT--
38Array
39(
40    [0] => Array
41        (
42            [t] =>  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
43        )
44
45)
46