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