server.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @version v5.20.17 31-Mar-2020
  4. * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. * Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. */
  10. /* Documentation on usage is at http://adodb.org/dokuwiki/doku.php?id=v5:proxy:proxy_index
  11. *
  12. * Legal query string parameters:
  13. *
  14. * sql = holds sql string
  15. * nrows = number of rows to return
  16. * offset = skip offset rows of data
  17. * fetch = $ADODB_FETCH_MODE
  18. *
  19. * example:
  20. *
  21. * http://localhost/php/server.php?select+*+from+table&nrows=10&offset=2
  22. */
  23. /*
  24. * Define the IP address you want to accept requests from
  25. * as a security measure. If blank we accept anyone promisciously!
  26. */
  27. $ACCEPTIP = '127.0.0.1';
  28. /*
  29. * Connection parameters
  30. */
  31. $driver = 'mysql';
  32. $host = 'localhost'; // DSN for odbc
  33. $uid = 'root';
  34. $pwd = 'garbase-it-is';
  35. $database = 'test';
  36. /*============================ DO NOT MODIFY BELOW HERE =================================*/
  37. // $sep must match csv2rs() in adodb.inc.php
  38. $sep = ' :::: ';
  39. include('./adodb.inc.php');
  40. include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
  41. function err($s)
  42. {
  43. die('**** '.$s.' ');
  44. }
  45. // undo stupid magic quotes
  46. function undomq(&$m)
  47. {
  48. if (get_magic_quotes_gpc()) {
  49. // undo the damage
  50. $m = str_replace('\\\\','\\',$m);
  51. $m = str_replace('\"','"',$m);
  52. $m = str_replace('\\\'','\'',$m);
  53. }
  54. return $m;
  55. }
  56. ///////////////////////////////////////// DEFINITIONS
  57. $remote = $_SERVER["REMOTE_ADDR"];
  58. if (!empty($ACCEPTIP))
  59. if ($remote != '127.0.0.1' && $remote != $ACCEPTIP)
  60. err("Unauthorised client: '$remote'");
  61. if (empty($_REQUEST['sql'])) err('No SQL');
  62. $conn = ADONewConnection($driver);
  63. if (!$conn->Connect($host,$uid,$pwd,$database)) err($conn->ErrorNo(). $sep . $conn->ErrorMsg());
  64. $sql = undomq($_REQUEST['sql']);
  65. if (isset($_REQUEST['fetch']))
  66. $ADODB_FETCH_MODE = $_REQUEST['fetch'];
  67. if (isset($_REQUEST['nrows'])) {
  68. $nrows = $_REQUEST['nrows'];
  69. $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : -1;
  70. $rs = $conn->SelectLimit($sql,$nrows,$offset);
  71. } else
  72. $rs = $conn->Execute($sql);
  73. if ($rs){
  74. //$rs->timeToLive = 1;
  75. echo _rs2serialize($rs,$conn,$sql);
  76. $rs->Close();
  77. } else
  78. err($conn->ErrorNo(). $sep .$conn->ErrorMsg());