pdo_mysql_bit.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. MySQL PDO->exec(), BIT columns - remove after fix!
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
  6. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  7. MySQLPDOTest::skip();
  8. if (MySQLPDOTest::isPDOMySQLnd())
  9. die("skip Known bug - mysqlnd handles BIT incorrectly!");
  10. ?>
  11. --FILE--
  12. <?php
  13. /* TODO: remove this test after fix and enable the BIT test in pdo_mysql_types.phpt again */
  14. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  15. function test_type(&$db, $offset, $sql_type, $value, $ret_value = NULL, $pattern = NULL) {
  16. $db->exec('DROP TABLE IF EXISTS test');
  17. $sql = sprintf('CREATE TABLE test(id INT, label %s) ENGINE=%s', $sql_type, MySQLPDOTest::getTableEngine());
  18. @$db->exec($sql);
  19. if ($db->errorCode() != 0) {
  20. // not all MySQL Server versions and/or engines might support the type
  21. return true;
  22. }
  23. $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (?, ?)');
  24. $stmt->bindValue(1, $offset);
  25. $stmt->bindValue(2, $value);
  26. if (!$stmt->execute()) {
  27. printf("[%03d + 1] INSERT failed, %s\n", $offset, var_export($stmt->errorInfo(), true));
  28. return false;
  29. }
  30. $stmt = $db->query('SELECT id, label FROM test');
  31. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  32. var_dump($row);
  33. var_dump($value);
  34. return true;
  35. }
  36. $db = MySQLPDOTest::factory();
  37. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  38. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  39. $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
  40. test_type($db, 20, 'BIT(8)', 1);
  41. echo "done!\n";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. require dirname(__FILE__) . '/mysql_pdo_test.inc';
  46. $db = MySQLPDOTest::factory();
  47. $db->exec('DROP TABLE IF EXISTS test');
  48. ?>
  49. --EXPECT--
  50. array(2) {
  51. ["id"]=>
  52. string(2) "20"
  53. ["label"]=>
  54. string(1) "1"
  55. }
  56. int(1)
  57. done!