mysql_deprecated_api.phpt 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. --TEST--
  2. Check if deprecated API calls bail out
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --INI--
  9. mysql.trace_mode=1
  10. error_reporting=E_ALL | E_NOTICE | E_STRICT
  11. --FILE--
  12. <?php
  13. /*
  14. We use an extra test to cover deprecation warning.
  15. Due to this extra test we can silence deprecation warnings
  16. in have other test using @ operator without loosing the information
  17. which function is deprecated and, without reducing test portability.
  18. */
  19. include "table.inc";
  20. if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
  21. $error = NULL;
  22. ob_start();
  23. if (!$res = mysql_db_query($db, "SELECT * FROM test", $link))
  24. $error .= sprintf("[001] [%d] %s\n", mysql_errno($link), mysql_error($link));
  25. else
  26. mysql_free_result($res);
  27. $output = ob_get_contents();
  28. ob_end_clean();
  29. if (!stristr($output, 'deprecated')) {
  30. printf("[002] mysql_db_query has been deprecated in 5.3.0\n");
  31. }
  32. /*
  33. Deprecated since 2002 or the like but documented to be deprecated since 5.3.
  34. In 5.3 and before the deprecation message was bound to mysql.trace_mode=1.
  35. In 5.3.99 the warning will always be thrown, independent of the mysql.trace_mode
  36. setting.
  37. */
  38. $error = NULL;
  39. ob_start();
  40. if (!$query = mysql_escape_string("charsets will be ignored"))
  41. $error .= sprintf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
  42. $output = ob_get_contents();
  43. ob_end_clean();
  44. if (!stristr($output, 'deprecated')) {
  45. printf("[006] mysql_escape_string has been deprecated in 5.3.0\n");
  46. }
  47. }
  48. if (version_compare(PHP_VERSION, '5.3.99') >= 0) {
  49. $error = NULL;
  50. ob_start();
  51. if (!$res = mysql_list_dbs($link))
  52. $error .= sprintf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
  53. else
  54. mysql_free_result($res);
  55. $output = ob_get_contents();
  56. ob_end_clean();
  57. if (!stristr($output, 'deprecated')) {
  58. printf("[004] mysql_db_query has been deprecated in 5.3.0\n");
  59. }
  60. }
  61. print "done!";
  62. ?>
  63. --CLEAN--
  64. <?php
  65. require_once("clean_table.inc");
  66. ?>
  67. --EXPECTF--
  68. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  69. done!