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