summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql/tests/pdo_mysql_attr_init_command.phpt
blob: b12161d4f3e34ecb076a07ec9b0e775a91aed216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--TEST--
PDO::MYSQL_ATTR_INIT_COMMAND
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
?>
--INI--
error_reporting=E_ALL
--FILE--
<?php
    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

    $dsn = MySQLPDOTest::getDSN();
    $user = PDO_MYSQL_TEST_USER;
    $pass = PDO_MYSQL_TEST_PASS;

    $table = sprintf("test_%s", md5(mt_rand(0, PHP_INT_MAX)));
    $db = new PDO($dsn, $user, $pass);
    $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));

    $create = sprintf('CREATE TABLE %s(id INT)', $table);
    var_dump($create);
    $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => $create));
    $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

    $info = $db->errorInfo();
    var_dump($info[0]);

    $db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table));
    $stmt = $db->query(sprintf('SELECT id FROM %s', $table));
    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));

    $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table));
    print "done!";
?>
--EXPECTF--
string(58) "CREATE TABLE test_%s(id INT)"
string(5) "00000"
array(1) {
  [0]=>
  array(1) {
    ["id"]=>
    string(1) "1"
  }
}
done!