pdo_038.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. PDOStatement::fetchColumn() invalid column index
  3. --SKIPIF--
  4. <?php # vim:ft=php
  5. if (!extension_loaded('pdo')) die('skip');
  6. $dir = getenv('REDIR_TEST_DIR');
  7. if (false == $dir) die('skip no driver');
  8. require_once $dir . 'pdo_test.inc';
  9. PDOTest::skip();
  10. ?>
  11. --FILE--
  12. <?php
  13. if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
  14. require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
  15. function fetchColumn($stmt, $index) {
  16. $stmt->execute();
  17. return $stmt->fetchColumn($index);
  18. }
  19. $conn = PDOTest::factory();
  20. $query = 'SELECT 1';
  21. switch ($conn->getAttribute(PDO::ATTR_DRIVER_NAME)) {
  22. case 'oci':
  23. $query .= ' FROM DUAL';
  24. break;
  25. case 'firebird':
  26. $query .= ' FROM RDB$DATABASE';
  27. break;
  28. }
  29. $stmt = $conn->prepare($query);
  30. var_dump(fetchColumn($stmt, -1));
  31. var_dump(fetchColumn($stmt, 0));
  32. var_dump(fetchColumn($stmt, 1));
  33. ?>
  34. --EXPECTF--
  35. Warning: PDOStatement::fetchColumn(): SQLSTATE[HY000]: General error: Invalid column index in %s
  36. bool(false)
  37. string(1) "1"
  38. Warning: PDOStatement::fetchColumn(): SQLSTATE[HY000]: General error: Invalid column index in %s
  39. bool(false)