1--TEST--
2MySQL PDOStatement->columnCount()
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9$db = MySQLPDOTest::factory();
10?>
11--FILE--
12<?php
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $db = MySQLPDOTest::factory();
15    MySQLPDOTest::createTestTable($db);
16
17    // The only purpose of this is to check if emulated and native PS
18  // return the same. If it works for one, it should work for all.
19    // Internal data structures should be the same in both cases.
20    printf("Testing emulated PS...\n");
21    try {
22        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
23        if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
24            printf("[002] Unable to turn on emulated prepared statements\n");
25
26        $stmt = $db->prepare("SELECT id, label, '?' as foo FROM test");
27        $stmt->execute();
28        var_dump($stmt->columnCount());
29
30        $stmt = $db->query('SELECT * FROM test');
31        var_dump($stmt->columnCount());
32
33    } catch (PDOException $e) {
34        printf("[001] %s [%s] %s\n",
35            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
36    }
37
38    printf("Testing native PS...\n");
39    try {
40        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
41        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
42            printf("[004] Unable to turn off emulated prepared statements\n");
43
44        $stmt = $db->prepare("SELECT id, label, '?' as foo, 'TODO - Stored Procedure' as bar FROM test");
45        $stmt->execute();
46        var_dump($stmt->columnCount());
47
48        $stmt = $db->query('SELECT * FROM test');
49        var_dump($stmt->columnCount());
50
51    } catch (PDOException $e) {
52        printf("[003] %s [%s] %s\n",
53            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
54    }
55
56    print "done!";
57?>
58--CLEAN--
59<?php
60require __DIR__ . '/mysql_pdo_test.inc';
61MySQLPDOTest::dropTestTable();
62?>
63--EXPECT--
64Testing emulated PS...
65int(3)
66int(2)
67Testing native PS...
68int(4)
69int(2)
70done!
71