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