bug70384.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. mysqli_float_handling - ensure 4 byte float is handled correctly
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. if (@$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  9. if ($link->server_version < 50709) {
  10. die("skip MySQL 5.7.9+ needed. Found [".
  11. intval(substr($link->server_version."", -5, 1)).
  12. ".".
  13. intval(substr($link->server_version."", -4, 2)).
  14. ".".
  15. intval(substr($link->server_version."", -2, 2)).
  16. "]");
  17. }
  18. }
  19. ?>
  20. --FILE--
  21. <?php
  22. require('connect.inc');
  23. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  24. printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  25. die();
  26. }
  27. if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
  28. printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  29. die();
  30. }
  31. if (!mysqli_query($link, "CREATE TABLE test(jsfield JSON) ENGINE = InnoDB")) {
  32. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  33. die();
  34. }
  35. $jsfield_data = '{"aaa": 123}';
  36. // Insert via string to make sure the real floating number gets to the DB
  37. if (!mysqli_query($link, "INSERT INTO test VALUES ('".$jsfield_data."')")) {
  38. printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  39. die();
  40. }
  41. if (!($res = mysqli_query($link, "SELECT * FROM test"))) {
  42. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. die();
  44. }
  45. $rows = $res->fetch_all();
  46. if (json_encode($rows[0][0]) != json_encode($jsfield_data)) {
  47. printf("[006] Data differs");
  48. var_dump(json_encode($rows[0][0]) != json_encode($jsfield_data));
  49. die();
  50. }
  51. mysqli_close($link);
  52. echo "OK";
  53. ?>
  54. --CLEAN--
  55. <?php
  56. require_once("clean_table.inc");
  57. ?>
  58. --EXPECT--
  59. OK