1--TEST-- 2PDOStatement::fetchColumn() invalid column index 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 17function fetchColumn($stmt, $index) { 18 $stmt->execute(); 19 return $stmt->fetchColumn($index); 20} 21 22$conn = PDOTest::factory(); 23$query = 'SELECT 1'; 24 25switch ($conn->getAttribute(PDO::ATTR_DRIVER_NAME)) { 26 case 'oci': 27 $query .= ' FROM DUAL'; 28 break; 29 case 'firebird': 30 $query .= ' FROM RDB$DATABASE'; 31 break; 32} 33 34$stmt = $conn->prepare($query); 35 36try { 37 var_dump(fetchColumn($stmt, -1)); 38} catch (\ValueError $e) { 39 echo $e->getMessage(), \PHP_EOL; 40} 41var_dump(fetchColumn($stmt, 0)); 42try { 43 var_dump(fetchColumn($stmt, 1)); 44} catch (\ValueError $e) { 45 echo $e->getMessage(), \PHP_EOL; 46} 47?> 48--EXPECT-- 49Column index must be greater than or equal to 0 50string(1) "1" 51Invalid column index 52