xref: /PHP-8.4/ext/pdo/tests/pdo_020.phpt (revision f4a5db3e)
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 test020(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
19$db->exec("INSERT INTO test020 VALUES(1, 'A', 'A')");
20$db->exec("INSERT INTO test020 VALUES(2, 'B', 'B')");
21$db->exec("INSERT INTO test020 VALUES(3, 'C', 'C')");
22
23foreach (array('SELECT id, val FROM test020', 'SELECT id, val, val2 FROM test020', 'SELECT COUNT(*) FROM test020') 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--CLEAN--
33<?php
34require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
35$db = PDOTest::factory();
36PDOTest::dropTableIfExists($db, "test020");
37?>
38--EXPECT--
39Counted 2 columns after SELECT id, val FROM test020.
40Counted 3 columns after SELECT id, val, val2 FROM test020.
41Counted 1 columns after SELECT COUNT(*) FROM test020.
42