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