xref: /PHP-5.3/ext/pdo/tests/pdo_020.phpt (revision 0a2e6f72)
1--TEST--
2PDO Common: PDOStatement::columnCount
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');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15$db = PDOTest::factory();
16
17$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
18$db->exec("INSERT INTO test VALUES(1, 'A', 'A')");
19$db->exec("INSERT INTO test VALUES(2, 'B', 'B')");
20$db->exec("INSERT INTO test VALUES(3, 'C', 'C')");
21
22foreach (array('SELECT id, val FROM test', 'SELECT id, val, val2 FROM test', 'SELECT COUNT(*) FROM test') as $sql) {
23
24	$stmt = $db->query($sql);
25	$res = $stmt->columnCount();
26    echo "Counted $res columns after $sql.\n";
27	$stmt = null;
28}
29
30?>
31--EXPECT--
32Counted 2 columns after SELECT id, val FROM test.
33Counted 3 columns after SELECT id, val, val2 FROM test.
34Counted 1 columns after SELECT COUNT(*) FROM test.
35