PageRenderTime 62ms CodeModel.GetById 12ms RepoModel.GetById 5ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_query_load_data_openbasedir.php

http://github.com/facebook/hiphop-php
PHP | 84 lines | 69 code | 14 blank | 1 comment | 18 complexity | b09aa18238f37f7752d329410c736a4c MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. @include_once("connect.inc");
  3. ini_set("open_basedir", __DIR__);
  4. chdir(__DIR__);
  5. if (!isset($db)) {
  6. // run-tests, I love you for not allowing me to set ini settings dynamically
  7. print "[006] [1148] The used command is not allowed with this MySQL version
  8. [007] [0]
  9. [008] LOAD DATA not run?
  10. [010] [1148] The used command is not allowed with this MySQL version
  11. done!";
  12. die();
  13. }
  14. require('table.inc');
  15. mysql_close($link);
  16. if ($socket)
  17. $host = sprintf("%s:%s", $host, $socket);
  18. else if ($port)
  19. $host = sprintf("%s:%s", $host, $port);
  20. if (!$link = mysql_connect($host, $user, $passwd, true, 128)) {
  21. printf("[001] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
  22. $host, $user, $passwd,
  23. mysql_errno(), mysql_error());
  24. }
  25. if (!mysql_select_db($db, $link)) {
  26. printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
  27. }
  28. if (file_exists('./simple.csv'))
  29. unlink('./simple.csv');
  30. if (!$fp = fopen('./simple.csv', 'w'))
  31. printf("[003] Cannot open CSV file\n");
  32. if (version_compare(PHP_VERSION, '5.9.9', '>') >= 0) {
  33. if (!fwrite($fp, (binary)"'97';'x';\n") ||
  34. !fwrite($fp, (binary)"'98';'y';\n") ||
  35. !fwrite($fp, (binary)"99;'z';\n")) {
  36. printf("[004] Cannot write CVS file '%s'\n", $file);
  37. }
  38. } else {
  39. if (!fwrite($fp, "97;'x';\n") ||
  40. !fwrite($fp, "98;'y';\n") ||
  41. !fwrite($fp, "99;'z';\n")) {
  42. printf("[005] Cannot write CVS file '%s'\n", $file);
  43. }
  44. }
  45. fclose($fp);
  46. $sql = sprintf("LOAD DATA LOCAL INFILE '%s'
  47. INTO TABLE test
  48. FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
  49. LINES TERMINATED BY '\n'",
  50. mysql_real_escape_string(realpath('./simple.csv'), $link));
  51. if (!mysql_query($sql, $link))
  52. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  53. if (!($res = mysql_query('SELECT label FROM test WHERE id = 97', $link)) ||
  54. !($row = mysql_fetch_assoc($res)) ||
  55. !mysql_free_result($res))
  56. printf("[007] [%d] '%s'\n", mysql_errno($link), mysql_error($link));
  57. if ($row['label'] != "x")
  58. printf("[008] LOAD DATA not run?\n");
  59. if (!mysql_query('DELETE FROM test', $link))
  60. printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
  61. $sql = "LOAD DATA LOCAL INFILE '/tmp/idonotexist'
  62. INTO TABLE test
  63. FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
  64. LINES TERMINATED BY '\n'";
  65. if (!mysql_query($sql, $link))
  66. printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
  67. mysql_close($link);
  68. unlink("./simple.csv");
  69. print "done!";
  70. ?>