xref: /PHP-8.3/ext/pdo/tests/pdo_022.phpt (revision 74859783)
1--TEST--
2PDO Common: PDOStatement::getColumnMeta
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 * Note well: meta information is a nightmare to handle portably.
13 * it's not really PDOs job.
14 * We've not yet defined exactly what makes sense for getColumnMeta,
15 * so no tests make any sense to anyone.  When they do, we can enable
16 * this test file.
17 * TODO: filter out driver dependent components from this common core
18 * test file.
19 */
20?>
21--XFAIL--
22This feature is not yet finalized, no test makes sense
23--FILE--
24<?php
25if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
26require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
27$db = PDOTest::factory();
28
29$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
30
31$data = array(
32    array('10', 'Abc', 'zxy'),
33    array('20', 'Def', 'wvu'),
34    array('30', 'Ghi', 'tsr'),
35    array('40', 'Jkl', 'qpo'),
36    array('50', 'Mno', 'nml'),
37    array('60', 'Pqr', 'kji'),
38);
39
40// Insert using question mark placeholders
41$stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)");
42foreach ($data as $row) {
43    $stmt->execute($row);
44}
45
46// Retrieve column metadata for a result set returned by explicit SELECT
47$select = $db->query('SELECT id, val, val2 FROM test');
48$meta = $select->getColumnMeta(0);
49var_dump($meta);
50$meta = $select->getColumnMeta(1);
51var_dump($meta);
52$meta = $select->getColumnMeta(2);
53var_dump($meta);
54
55// Retrieve column metadata for a result set returned by a function
56$select = $db->query('SELECT COUNT(*) FROM test');
57$meta = $select->getColumnMeta(0);
58var_dump($meta);
59
60?>
61--EXPECT--
62The unexpected!
63