PageRenderTime 381ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/libraries/sqlvalidator.lib.php

https://bitbucket.org/adarshj/convenient_website
PHP | 98 lines | 29 code | 13 blank | 56 comment | 9 complexity | e4d849b06cb93f67c84be831c6a6795b MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * SQL Validator interface for phpMyAdmin
  5. *
  6. * Copyright 2002 Robin Johnson <robbat2@users.sourceforge.net>
  7. * http://www.orbis-terrarum.net/?l=people.robbat2
  8. *
  9. * This function uses the Mimer SQL Validator service
  10. * <http://developer.mimer.com/validator/index.htm> from phpMyAdmin
  11. *
  12. * Copyright for Server side validator systems:
  13. * "All SQL statements are stored anonymously for statistical purposes.
  14. * Mimer SQL Validator, Copyright 2002 Upright Database Technology.
  15. * All rights reserved."
  16. *
  17. * All data is transported over HTTP-SOAP
  18. * And uses the PEAR SOAP Module
  19. *
  20. * Install instructions for PEAR SOAP
  21. * Make sure you have a really recent PHP with PEAR support
  22. * run this: "pear install Mail_Mime Net_DIME SOAP"
  23. *
  24. * Enable the SQL Validator options in the configuration file
  25. * $cfg['SQLQuery']['Validate'] = true;
  26. * $cfg['SQLValidator']['use'] = true;
  27. *
  28. * Also set a username and password if you have a private one
  29. *
  30. * @package PhpMyAdmin
  31. */
  32. if (! defined('PHPMYADMIN')) {
  33. exit;
  34. }
  35. /**
  36. * We need the PEAR libraries, so do a minimum version check first
  37. * I'm not sure if PEAR was available before this point
  38. * For now we actually use a configuration flag
  39. */
  40. if ($cfg['SQLValidator']['use'] == true) {
  41. include_once './libraries/sqlvalidator.class.php';
  42. } // if ($cfg['SQLValidator']['use'] == true)
  43. /**
  44. * This function utilizes the Mimer SQL Validator service
  45. * to validate an SQL query
  46. *
  47. * <http://developer.mimer.com/validator/index.htm>
  48. *
  49. * @param string SQL query to validate
  50. *
  51. * @return string Validator result string
  52. *
  53. * @global array The PMA configuration array
  54. */
  55. function PMA_validateSQL($sql)
  56. {
  57. global $cfg;
  58. $str = '';
  59. if ($cfg['SQLValidator']['use']) {
  60. if (isset($GLOBALS['sqlvalidator_error'])
  61. && $GLOBALS['sqlvalidator_error']) {
  62. $str = sprintf(__('The SQL validator could not be initialized. Please check if you have installed the necessary PHP extensions as described in the %sdocumentation%s.'), '<a href="./Documentation.html#faqsqlvalidator" target="documentation">', '</a>');
  63. } else {
  64. // create new class instance
  65. $srv = new PMA_SQLValidator();
  66. // Checks for username settings
  67. // The class defaults to anonymous with an empty password
  68. // automatically
  69. if ($cfg['SQLValidator']['username'] != '') {
  70. $srv->setCredentials($cfg['SQLValidator']['username'], $cfg['SQLValidator']['password']);
  71. }
  72. // Identify ourselves to the server properly...
  73. $srv->appendCallingProgram('phpMyAdmin', PMA_VERSION);
  74. // ... and specify what database system we are using
  75. $srv->setTargetDbms('MySQL', PMA_MYSQL_STR_VERSION);
  76. // Log on to service
  77. $srv->start();
  78. // Do service validation
  79. $str = $srv->validationString($sql);
  80. }
  81. } // end if
  82. // Gives string back to caller
  83. return $str;
  84. } // end of the "PMA_validateSQL()" function
  85. ?>