home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / sqlvalidator.class.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  13.3 KB  |  410 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * PHP interface to MimerSQL Validator
  5. *
  6. * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
  7. * http://www.orbis-terrarum.net/?l=people.robbat2
  8. *
  9. * All data is transported over HTTP-SOAP
  10. * And uses the PEAR SOAP Module
  11. *
  12. * Install instructions for PEAR SOAP
  13. * Make sure you have a really recent PHP with PEAR support
  14. * run this: "pear install Mail_Mime Net_DIME SOAP"
  15. *
  16. * If you got this file from somewhere other than phpMyAdmin
  17. * please be aware that the latest copy will always be in the
  18. * phpMyAdmin subversion tree as
  19. * $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/libraries/sqlvalidator.class.php $
  20. *
  21. * This code that also used to depend on the PHP overload module, but that has been
  22. * removed now.
  23. *
  24. * @access   public
  25. *
  26. * @author   Robin Johnson <robbat2@users.sourceforge.net>
  27. *
  28. * @version  $Id: sqlvalidator.class.php 10240 2007-04-01 11:02:46Z cybot_tm $
  29. */
  30.  
  31. @include_once 'SOAP/Client.php';
  32.  
  33. if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
  34.     $GLOBALS['sqlvalidator_error'] = TRUE;
  35. } else {
  36.     // Ok, we have SOAP Support, so let's use it!
  37.  
  38.     class PMA_SQLValidator {
  39.  
  40.         var $url;
  41.         var $service_name;
  42.         var $wsdl;
  43.         var $output_type;
  44.  
  45.         var $username;
  46.         var $password;
  47.         var $calling_program;
  48.         var $calling_program_version;
  49.         var $target_dbms;
  50.         var $target_dbms_version;
  51.         var $connectionTechnology;
  52.         var $connection_technology_version;
  53.         var $interactive;
  54.  
  55.         var $service_link = null;
  56.         var $session_data = null;
  57.  
  58.  
  59.         /**
  60.          * Private functions - You don't need to mess with these
  61.          */
  62.  
  63.         /**
  64.          * Service opening
  65.          *
  66.          * @param  string  URL of Mimer SQL Validator WSDL file
  67.          *
  68.          * @return object  Object to use
  69.          *
  70.          * @access private
  71.          */
  72.         function _openService($url)
  73.         {
  74.             $obj = new SOAP_Client($url, TRUE);
  75.             return $obj;
  76.         } // end of the "openService()" function
  77.  
  78.  
  79.         /**
  80.          * Service initializer to connect to server
  81.          *
  82.          * @param  object   Service object
  83.          * @param  string   Username
  84.          * @param  string   Password
  85.          * @param  string   Name of calling program
  86.          * @param  string   Version of calling program
  87.          * @param  string   Target DBMS
  88.          * @param  string   Version of target DBMS
  89.          * @param  string   Connection Technology
  90.          * @param  string   version of Connection Technology
  91.          * @param  integer  boolean of 1/0 to specify if we are an interactive system
  92.          *
  93.          * @return object   stdClass return object with data
  94.          *
  95.          * @access private
  96.          */
  97.         function _openSession($obj, $username, $password,
  98.                                       $calling_program, $calling_program_version,
  99.                                       $target_dbms, $target_dbms_version,
  100.                                       $connection_technology, $connection_technology_version,
  101.                                       $interactive)
  102.         {
  103.     $use_array = array("a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive);
  104.             $ret = $obj->call("openSession", $use_array);
  105.  
  106.            // This is the old version that needed the overload extension
  107.            /* $ret = $obj->openSession($username, $password,
  108.                                      $calling_program, $calling_program_version,
  109.                                      $target_dbms, $target_dbms_version,
  110.                                      $connection_technology, $connection_technology_version,
  111.                                      $interactive); */
  112.  
  113.             return $ret;
  114.         } // end of the "_openSession()" function
  115.  
  116.  
  117.         /**
  118.          * Validator sytem call
  119.          *
  120.          * @param  object  Service object
  121.          * @param  object  Session object
  122.          * @param  string  SQL Query to validate
  123.          * @param  string  Data return type
  124.          *
  125.          * @return object  stClass return with data
  126.          *
  127.          * @access private
  128.          */
  129.         function _validateSQL($obj, $session, $sql, $method)
  130.         {
  131.     $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
  132.             $res = $obj->call("validateSQL", $use_array);
  133.  
  134.            // This is the old version that needed the overload extension
  135.            // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
  136.             return $res;
  137.         } // end of the "validateSQL()" function
  138.  
  139.  
  140.         /**
  141.          * Validator sytem call
  142.          *
  143.          * @param  string  SQL Query to validate
  144.          *
  145.          * @return object  stdClass return with data
  146.          *
  147.          * @access private
  148.          *
  149.          * @see    validateSQL()
  150.          */
  151.         function _validate($sql)
  152.         {
  153.             $ret = $this->_validateSQL($this->service_link, $this->session_data,
  154.                                                $sql, $this->output_type);
  155.             return $ret;
  156.         } // end of the "validate()" function
  157.  
  158.  
  159.         /**
  160.          * Public functions
  161.          */
  162.  
  163.         /**
  164.          * Constructor
  165.          *
  166.          * @access public
  167.          */
  168.         function PMA_SQLValidator()
  169.         {
  170.             $this->url                           = 'http://sqlvalidator.mimer.com/v1/services';
  171.             $this->service_name                  = 'SQL99Validator';
  172.             $this->wsdl                          = '?wsdl';
  173.  
  174.             $this->output_type                   = 'html';
  175.  
  176.             $this->username                      = 'anonymous';
  177.             $this->password                      = '';
  178.             $this->calling_program               = 'PHP_SQLValidator';
  179.             $this->calling_program_version       = '$Revision: 10240 $';
  180.             $this->target_dbms                   = 'N/A';
  181.             $this->target_dbms_version           = 'N/A';
  182.             $this->connection_technology         = 'PHP';
  183.             $this->connection_technology_version = phpversion();
  184.             $this->interactive = 1;
  185.  
  186.             $this->service_link = null;
  187.             $this->session_data = null;
  188.         } // end of the "PMA_SQLValidator()" function
  189.  
  190.  
  191.         /**
  192.          * Sets credentials
  193.          *
  194.          * @param  string  the username
  195.          * @param  string  the password
  196.          *
  197.          * @access public
  198.          */
  199.         function setCredentials($username, $password)
  200.         {
  201.             $this->username = $username;
  202.             $this->password = $password;
  203.         } // end of the "setCredentials()" function
  204.  
  205.  
  206.         /**
  207.          * Sets the calling program
  208.          *
  209.          * @param  string  the calling program name
  210.          * @param  string  the calling program revision
  211.          *
  212.          * @access public
  213.          */
  214.         function setCallingProgram($calling_program, $calling_program_version)
  215.         {
  216.             $this->calling_program         = $calling_program;
  217.             $this->calling_program_version = $calling_program_version;
  218.         } // end of the "setCallingProgram()" function
  219.  
  220.  
  221.         /**
  222.          * Appends the calling program
  223.          *
  224.          * @param  string  the calling program name
  225.          * @param  string  the calling program revision
  226.          *
  227.          * @access public
  228.          */
  229.         function appendCallingProgram($calling_program, $calling_program_version)
  230.         {
  231.             $this->calling_program         .= ' - ' . $calling_program;
  232.             $this->calling_program_version .= ' - ' . $calling_program_version;
  233.         } // end of the "appendCallingProgram()" function
  234.  
  235.  
  236.         /**
  237.          * Sets the target DBMS
  238.          *
  239.          * @param  string  the target DBMS name
  240.          * @param  string  the target DBMS revision
  241.          *
  242.          * @access public
  243.          */
  244.         function setTargetDbms($target_dbms, $target_dbms_version)
  245.         {
  246.             $this->target_dbms         = $target_dbms;
  247.             $this->target_dbms_version = $target_dbms_version;
  248.         } // end of the "setTargetDbms()" function
  249.  
  250.  
  251.         /**
  252.          * Appends the target DBMS
  253.          *
  254.          * @param  string  the target DBMS name
  255.          * @param  string  the target DBMS revision
  256.          *
  257.          * @access public
  258.          */
  259.         function appendTargetDbms($target_dbms, $target_dbms_version)
  260.         {
  261.             $this->target_dbms         .= ' - ' . $target_dbms;
  262.             $this->target_dbms_version .= ' - ' . $target_dbms_version;
  263.         } // end of the "appendTargetDbms()" function
  264.  
  265.  
  266.         /**
  267.          * Sets the connection technology used
  268.          *
  269.          * @param  string  the connection technology name
  270.          * @param  string  the connection technology revision
  271.          *
  272.          * @access public
  273.          */
  274.         function setConnectionTechnology($connection_technology, $connection_technology_version)
  275.         {
  276.             $this->connection_technology         = $connection_technology;
  277.             $this->connection_technology_version = $connection_technology_version;
  278.         } // end of the "setConnectionTechnology()" function
  279.  
  280.  
  281.         /**
  282.          * Appends the connection technology used
  283.          *
  284.          * @param  string  the connection technology name
  285.          * @param  string  the connection technology revision
  286.          *
  287.          * @access public
  288.          */
  289.         function appendConnectionTechnology($connection_technology, $connection_technology_version)
  290.         {
  291.             $this->connection_technology         .= ' - ' . $connection_technology;
  292.             $this->connection_technology_version .= ' - ' . $connection_technology_version;
  293.         } // end of the "appendConnectionTechnology()" function
  294.  
  295.  
  296.         /**
  297.          * Sets whether interactive mode should be used or not
  298.          *
  299.          * @param  integer  whether interactive mode should be used or not
  300.          *
  301.          * @access public
  302.          */
  303.         function setInteractive($interactive)
  304.         {
  305.             $this->interactive = $interactive;
  306.         } // end of the "setInteractive()" function
  307.  
  308.  
  309.         /**
  310.          * Sets the output type to use
  311.          *
  312.          * @param  string  the output type to use
  313.          *
  314.          * @access public
  315.          */
  316.         function setOutputType($output_type)
  317.         {
  318.             $this->output_type = $output_type;
  319.         } // end of the "setOutputType()" function
  320.  
  321.  
  322.         /**
  323.          * Starts service
  324.          *
  325.          * @access public
  326.          */
  327.         function startService()
  328.         {
  329.  
  330.             $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
  331.  
  332.         } // end of the "startService()" function
  333.  
  334.  
  335.         /**
  336.          * Starts session
  337.          *
  338.          * @access public
  339.          */
  340.         function startSession()
  341.         {
  342.             $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
  343.                                                               $this->calling_program, $this->calling_program_version,
  344.                                                               $this->target_dbms, $this->target_dbms_version,
  345.                                                               $this->connection_technology, $this->connection_technology_version,
  346.                                                               $this->interactive);
  347.  
  348.             if (isset($this->session_data) && ($this->session_data != null)
  349.                 && ($this->session_data->target != $this->url)) {
  350.                 // Reopens the service on the new URL that was provided
  351.                 $url = $this->session_data->target;
  352.                 $this->startService();
  353.             }
  354.         } // end of the "startSession()" function
  355.  
  356.  
  357.         /**
  358.          * Do start service and session
  359.          *
  360.          * @access public
  361.          */
  362.         function start()
  363.         {
  364.             $this->startService();
  365.             $this->startSession();
  366.         } // end of the "start()" function
  367.  
  368.  
  369.         /**
  370.          * Call to determine just if a query is valid or not.
  371.          *
  372.          * @param  string SQL statement to validate
  373.          *
  374.          * @return string Validator string from Mimer
  375.          *
  376.          * @see _validate
  377.          */
  378.         function isValid($sql)
  379.         {
  380.             $res = $this->_validate($sql);
  381.             return $res->standard;
  382.         } // end of the "isValid()" function
  383.  
  384.  
  385.         /**
  386.          * Call for complete validator response
  387.          *
  388.          * @param  string SQL statement to validate
  389.          *
  390.          * @return string Validator string from Mimer
  391.          *
  392.          * @see _validate
  393.          */
  394.         function validationString($sql)
  395.         {
  396.             $res = $this->_validate($sql);
  397.             return $res->data;
  398.  
  399.         } // end of the "validationString()" function
  400.     } // end class PMA_SQLValidator
  401.  
  402.     //add an extra check to ensure that the class was defined without errors
  403.     if (!class_exists('PMA_SQLValidator')) {
  404.         $GLOBALS['sqlvalidator_error'] = TRUE;
  405.     }
  406.  
  407. } // end else
  408.  
  409. ?>
  410.