Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / sqlvalidator.lib.php
blobde55e9a1723f8482b3055be80cce6806cffc5266
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * SQL Validator interface for phpMyAdmin
6 * Copyright 2002 Robin Johnson <robbat2@users.sourceforge.net>
7 * http://www.orbis-terrarum.net/?l=people.robbat2
9 * This function uses the Mimer SQL Validator service
10 * <http://developer.mimer.com/validator/index.htm> from phpMyAdmin
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."
17 * All data is transported over HTTP-SOAP
18 * And uses the PEAR SOAP Module
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"
24 * Enable the SQL Validator options in the configuration file
25 * $cfg['SQLQuery']['Validate'] = true;
26 * $cfg['SQLValidator']['use'] = true;
28 * Also set a username and password if you have a private one
30 * @package PhpMyAdmin
32 if (! defined('PHPMYADMIN')) {
33 exit;
36 /**
37 * We need the PEAR libraries, so do a minimum version check first
38 * I'm not sure if PEAR was available before this point
39 * For now we actually use a configuration flag
41 if ($cfg['SQLValidator']['use'] == true) {
42 include_once './libraries/sqlvalidator.class.php';
43 } // if ($cfg['SQLValidator']['use'] == true)
46 /**
47 * This function utilizes the Mimer SQL Validator service
48 * to validate an SQL query
50 * <http://developer.mimer.com/validator/index.htm>
52 * @param string $sql SQL query to validate
54 * @return string Validator result string
56 * @global array The PMA configuration array
58 function PMA_validateSQL($sql)
60 global $cfg;
62 $str = '';
64 if ($cfg['SQLValidator']['use']) {
65 if (isset($GLOBALS['sqlvalidator_error'])
66 && $GLOBALS['sqlvalidator_error']
67 ) {
68 $str = sprintf(
69 __('The SQL validator could not be initialized. Please check if you have installed the necessary PHP extensions as described in the %sdocumentation%s.'),
70 '<a href="' . PMA_Util::getDocuLink('faq', 'faqsqlvalidator') . '" target="documentation">',
71 '</a>'
73 } else {
74 // create new class instance
75 $srv = new PMA_SQLValidator();
77 // Checks for username settings
78 // The class defaults to anonymous with an empty password
79 // automatically
80 if ($cfg['SQLValidator']['username'] != '') {
81 $srv->setCredentials(
82 $cfg['SQLValidator']['username'],
83 $cfg['SQLValidator']['password']
87 // Identify ourselves to the server properly...
88 $srv->appendCallingProgram('phpMyAdmin', PMA_VERSION);
90 // ... and specify what database system we are using
91 $srv->setTargetDbms('MySQL', PMA_MYSQL_STR_VERSION);
93 // Log on to service
94 $srv->start();
96 // Do service validation
97 $str = $srv->validationString($sql);
100 } // end if
102 // Gives string back to caller
103 return $str;
104 } // end of the "PMA_validateSQL()" function