Advertisement
Guest User

Untitled

a guest
May 9th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.81 KB | None | 0 0
  1. <?php
  2. define("MySQL_MODE_ALL", chr(249) . chr(218) . chr(5) . "MySQL::MODE_ALL" . chr(5) . chr(218) . chr(249));
  3. define("MySQL_MODE_ONE", chr(249) . chr(218) . chr(5) . "MySQL::MODE_ONE" . chr(5) . chr(218) . chr(249));
  4. define("MySQL_MODE_GET", chr(249) . chr(218) . chr(5) . "MySQL::MODE_GET" . chr(5) . chr(218) . chr(249));
  5.  
  6. class MySQL
  7.     {
  8.     // +------------------------------------------------------------------+
  9.     // | Protected Variables                                              |
  10.     // +------------------------------------------------------------------+
  11.  
  12.     var $_credentials;
  13.     var $_conn;
  14.     var $_lastQuery;
  15.     var $_sqlError;
  16.     var $_sqlErrorLevel;
  17.     var $_debug;
  18.     var $_defaultMode;
  19.     var $_autoEscape;
  20.     var $_currentDb;
  21.  
  22.     // +------------------------------------------------------------------+
  23.     // | Class Constructor                                                |
  24.     // +------------------------------------------------------------------+
  25.  
  26.     function MySQL($server = null, $username = "", $password = "", $database = "")
  27.         {
  28.         $this->set_mode(MySQL_MODE_GET);
  29.         $this->use_auto_escape(true);
  30.         $this->use_debugging(false);
  31.         $this->use_strict_errors(true);
  32.  
  33.         $this->_conn = null;
  34.         $this->_lastError = null;
  35.         $this->_currentDb = null;
  36.  
  37.         if (!function_exists('mysql_connect'))
  38.                 trigger_error("MySQL support not enabled on PHP installation", E_USER_ERROR);
  39.  
  40.         if (!is_string($server))
  41.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be string, " . gettype($server) . " given", E_USER_ERROR);
  42.  
  43.         if (!is_string($username))
  44.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 2 to be string, " . gettype($username) . " given", E_USER_ERROR);
  45.  
  46.         if (!is_string($password))
  47.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 3 to be string, " . gettype($password) . " given", E_USER_ERROR);
  48.  
  49.         if (!is_string($database))
  50.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 4 to be string, " . gettype($database) . " given", E_USER_ERROR);
  51.  
  52.         $this->_credentials['server'] = $server;
  53.         $this->_credentials['user'] = $username;
  54.  
  55.         if ($username != "")
  56.                 $this->_credentials['pass'] = $password;
  57.         else
  58.                 $this->_credentials['pass'] = "";
  59.  
  60.         $this->_credentials['dbname'] = $database;
  61.         }
  62.  
  63.     function _sql_error($query = null)
  64.         {
  65.         $this->_sqlError=array();
  66.  
  67.         $this->_sqlError['errno'] = @mysql_errno();
  68.  
  69.         if ($this->_sqlError['errno'] == 1064)
  70.                 {
  71.                 $tmpMessage = @mysql_error();
  72.                 $wrkMessageA = $tmpMessage;
  73.  
  74.                 $wrkMessageB = strstr($wrkMessageA, 'at line');
  75.  
  76.                 if ($wrkMessageB === FALSE)
  77.                         { $this->_sqlError['message'] = $tmpMessage; }
  78.                 else
  79.                         {
  80.                         while ($wrkMessageA != $wrkMessageB)
  81.                                 {
  82.                                 $wrkMessageA = $wrkMessageB;
  83.                                 $wrkMessageB = strstr($wrkMessageA, 'at line');
  84.                                 }
  85.  
  86.                         $this->_sqlError['message'] = substr($tmpMessage, 0, strlen($wrkMessageB) * -1);
  87.                         }
  88.                 }
  89.         else
  90.                 { $this->_sqlError['message'] = @mysql_error(); }
  91.  
  92.         $this->_lastQuery = $query;
  93.  
  94.         if ($this->_debug && !is_null($this->_lastQuery))
  95.                 ErrorHandler::log(PEAR_LOG_NOTICE, 'failed query: ' . $this->_lastQuery);
  96.  
  97.         trigger_error('' . $this->_sqlError['errno'] . ' - ' . $this->_sqlError['message'], $this->_sqlErrorLevel);
  98.         }
  99.  
  100.     // +------------------------------------------------------------------+
  101.     // | Protected Methods - Sanitation                                   |
  102.     // +------------------------------------------------------------------+
  103.  
  104.     function _is_valid_mode($mode)
  105.         { return ($mode == MySQL_MODE_ONE || $mode == MySQL_MODE_ALL || $mode == MySQL_MODE_GET); }
  106.  
  107.     // +------------------------------------------------------------------+
  108.     // | Protected Methods - Helper Methods                               |
  109.     // +------------------------------------------------------------------+
  110.  
  111.     function _match_wildcard($pattern, $string)
  112.         {
  113.         $corr = addcslashes($pattern, '/\\.+^$(){}=!<>|');
  114.         $search=array
  115.                 (
  116.                 '_',
  117.                 '%',
  118.                 '\\\.?',
  119.                 '\\\.*'
  120.                 );
  121.  
  122.         $replace=array
  123.                 (
  124.                 '.?',
  125.                 '.*',
  126.                 '_',
  127.                 '%'
  128.                 );
  129.  
  130.         if (@preg_match('/^' . str_replace($search, $replace, $corr) . '$/i', $string) > 0)
  131.                 return true;
  132.         else
  133.                 return false;
  134.         }
  135.  
  136.     // +------------------------------------------------------------------+
  137.     // | Public Methods - Get/Set State                                   |
  138.     // +------------------------------------------------------------------+
  139.  
  140.     function get_last_error()
  141.         {
  142.         $lastError = $this->_sqlError;
  143.         $this->_sqlError = null;
  144.         return $lastError;
  145.         }
  146.  
  147.     function set_mode($mode = null)
  148.         {
  149.         if (!is_string($mode))
  150.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be boolean, " . gettype($mode) . " given", E_USER_WARNING);
  151.  
  152.         elseif (!$this->_is_valid_mode($mode))
  153.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be equal to either constant MySQL_MODE_ALL, MySQL_MODE_ONE, or MySQL_MODE_GET", E_USER_WARNING);
  154.  
  155.         else
  156.                 $this->_defaultMode = $mode;
  157.         }
  158.  
  159.     function use_auto_escape($autoEscape = null)
  160.         {
  161.         if (!is_bool($autoEscape))
  162.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be boolean, " . gettype($autoEscape) . " given", E_USER_WARNING);
  163.         else
  164.                 $this->_autoEscape = $autoEscape;
  165.         }
  166.  
  167.     function use_debugging($debug = null)
  168.         {
  169.         if (!is_bool($debug))
  170.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be boolean, " . gettype($debug) . " given", E_USER_WARNING);
  171.         else
  172.                 $this->_debug = $debug;
  173.         }
  174.  
  175.     function use_strict_errors($strictErrors = null)
  176.         {
  177.         if (!is_bool($strictErrors))
  178.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be boolean, " . gettype($strictErrors) . " given", E_USER_WARNING);
  179.  
  180.         elseif ($strictErrors === TRUE)
  181.                 $this->_sqlErrorLevel = E_USER_ERROR;
  182.  
  183.         else
  184.                 $this->_sqlErrorLevel = E_USER_WARNING;
  185.         }
  186.  
  187.     // +------------------------------------------------------------------+
  188.     // | Public Methods - Connection Handling                             |
  189.     // +------------------------------------------------------------------+
  190.  
  191.     function close()
  192.         {
  193.         if ($this->opened())
  194.                 trigger_error("Connection is already closed", E_USER_NOTICE);
  195.         else
  196.                 {
  197.                 if (@mysql_close($this->_conn) === FALSE)
  198.                         {
  199.                         $this->_sql_error();
  200.  
  201.                         return false;
  202.                         }
  203.                 else
  204.                         {
  205.                         $this->_conn = null;
  206.                         $this->_currentDb = null;
  207.                         }
  208.                 }
  209.  
  210.         return true;
  211.         }
  212.  
  213.     function open()
  214.         {
  215.         $this->_conn = @mysql_connect($this->_credentials['server'], $this->_credentials['user'], $this->_credentials['pass'], true);
  216.  
  217.         if ($this->_conn === FALSE)
  218.                 {
  219.                 $this->_sql_error();
  220.                 $this->_conn = null;
  221.  
  222.                 return false;
  223.                 }
  224.         elseif ($this->_credentials['dbname'] != '')
  225.                 {
  226.                 if ($this->select_db($this->_credentials['dbname']) === FALSE)
  227.                         {
  228.                         $this->close();
  229.  
  230.                         return false;
  231.                         }
  232.                 }
  233.  
  234.         return true;
  235.         }
  236.  
  237.     function opened()
  238.         { return !(is_null($this->_conn) || $this->_conn === FALSE); }
  239.  
  240.     // +------------------------------------------------------------------+
  241.     // | Public Methods - Database Navigation                             |
  242.     // +------------------------------------------------------------------+
  243.  
  244.     function select_db($database = null)
  245.         {
  246.         if (!is_string($database))
  247.                 {
  248.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be string, " . gettype($database) . " given", E_USER_WARNING);
  249.                 return false;
  250.                 }
  251.  
  252.         if (!$this->opened())
  253.                 {
  254.                 trigger_error('Not connected to MySQL Server', $this->_sqlErrorLevel);
  255.                 return false;
  256.                 }
  257.  
  258.         if ($database != '')
  259.                 {
  260.                 if (@mysql_select_db($database, $this->_conn) === FALSE)
  261.                         {
  262.                         $this->_sql_error();
  263.                         return false;
  264.                         }
  265.                 else
  266.                         { $this->_currentDb = $database; }
  267.                 }
  268.  
  269.         return true;
  270.         }
  271.  
  272.     // +------------------------------------------------------------------+
  273.     // | Public Methods - Dataset Management And Querying                 |
  274.     // +------------------------------------------------------------------+
  275.  
  276.     function count_affected()
  277.         {
  278.         if (!$this->opened())
  279.                 {
  280.                 trigger_error('Not connected to MySQL Server', $this->_sqlErrorLevel);
  281.  
  282.                 return 0;
  283.                 }
  284.         else
  285.                 { return@mysql_affected_rows($this->_conn); }
  286.         }
  287.  
  288.     function count($resultSet = NULL)
  289.         {
  290.         if (is_bool($resultSet))
  291.                 { return 0; }
  292.         elseif (is_array($resultSet))
  293.                 { return count($resultSet); }
  294.         elseif (is_null($resultSet))
  295.                 { return 0; }
  296.         elseif (!(is_resource($resultSet) && get_resource_type($resultSet) == 'mysql result'))
  297.                 {
  298.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be resource of type (mysql result), " . gettype($resultSet) . " given", E_USER_WARNING);
  299.                 return 0;
  300.                 }
  301.         else
  302.                 { return@mysql_num_rows($resultSet); }
  303.         }
  304.  
  305.     function create_value_list()
  306.         {
  307.         $numArgs = func_num_args();
  308.  
  309.         if ($numArgs < 1)
  310.                 {
  311.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects at least 1 parameter", E_USER_WARNING);
  312.                 return "('" . '\0\1\0' . "')";
  313.                 }
  314.  
  315.         if (!$this->opened())
  316.                 {
  317.                 trigger_error('Not connected to MySQL Server', $this->_sqlErrorLevel);
  318.                 return "('" . '\0\1\0' . "')";
  319.                 }
  320.  
  321.         $args = func_get_args();
  322.         $result = null;
  323.  
  324.         if (is_string($args[0]))
  325.                 {
  326.                 if (!$this->_is_valid_mode($args[count($args) - 1]))
  327.                         $args[] = MySQL_MODE_GET;
  328.                 else
  329.                         $args[count($args) - 1] = MySQL_MODE_GET;
  330.  
  331.                 $result = call_user_func_array(array
  332.                         (
  333.                         $this,
  334.                         "query"
  335.                         ), $args);
  336.                 }
  337.  
  338.         if (!is_null($result) || (is_resource($args[0]) && get_resource_type($args[0]) == 'mysql result'))
  339.                 {
  340.                 if (is_null($result))
  341.                         { $result = $args[0]; }
  342.  
  343.                 $key = null;
  344.                 $values=array();
  345.  
  346.                 while ($row = $this->fetch($result))
  347.                         {
  348.                         if (is_null($key))
  349.                                 {
  350.                                 $allkeys = array_keys($row);
  351.                                 $key = $allkeys[0];
  352.                                 }
  353.  
  354.                         $values[] = $this->escape($row[$key]);
  355.                         }
  356.  
  357.                 if (count($values) > 0)
  358.                         return "('" . implode("','", $values) . "')";
  359.                 else
  360.                         return "('" . '\0\1\0' . "')";
  361.                 }
  362.         elseif (is_array($args[0]))
  363.                 {
  364.                 if (count($args[0]) < 1)
  365.                         { return "('" . '\0\1\0' . "')"; }
  366.                 elseif (is_array($args[0][0]))
  367.                         {
  368.                         $key = null;
  369.                         $values=array();
  370.  
  371.                         foreach ($args[0] as $row)
  372.                                 {
  373.                                 if (is_null($key))
  374.                                         {
  375.                                         $allkeys = array_keys($row);
  376.                                         $key = $allkeys[0];
  377.                                         }
  378.  
  379.                                 $values[] = $this->escape($row[$key]);
  380.                                 }
  381.  
  382.                         if (count($values) > 0)
  383.                                 return "('" . implode("','", $values) . "')";
  384.                         else
  385.                                 return "('" . '\0\1\0' . "')";
  386.                         }
  387.                 else
  388.                         {
  389.                         $allkeys = array_keys($args[0]);
  390.                         return "('" . $this->escape($args[0][$allkeys[0]]) . "')";
  391.                         }
  392.                 }
  393.         elseif (is_null($args[0]))
  394.                 { return "('" . '\0\1\0' . "')"; }
  395.         else
  396.                 {
  397.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be resource of type array, (mysql result) or string, " . gettype($args[0]) . " given", E_USER_WARNING);
  398.                 return "('" . '\0\1\0' . "')";
  399.                 }
  400.         }
  401.  
  402.     function fetch($resultSet = NULL)
  403.         {
  404.         if (is_bool($resultSet))
  405.                 { return false; }
  406.         elseif (!(is_resource($resultSet) && get_resource_type($resultSet) == 'mysql result'))
  407.                 {
  408.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be resource of type (mysql result), " . gettype($resultSet) . " given", E_USER_WARNING);
  409.                 return false;
  410.                 }
  411.         else
  412.                 { return@mysql_fetch_array($resultSet); }
  413.         }
  414.  
  415.     function last_insert_id()
  416.         {
  417.         if (!$this->opened())
  418.                 {
  419.                 trigger_error('Not connected to MySQL Server', $this->_sqlErrorLevel);
  420.                 return false;
  421.                 }
  422.         else
  423.                 {
  424.                 $resultSet = $this->query("SELECT LAST_INSERT_ID() AS 'LastId';", MySQL_MODE_ONE);
  425.  
  426.                 if (!is_null($resultSet))
  427.                         { return $resultSet['LastId']; }
  428.                 else
  429.                         { return null; }
  430.                 }
  431.         }
  432.  
  433.     function query()
  434.         {
  435.         $numArgs = func_num_args();
  436.  
  437.         if ($numArgs < 1)
  438.                 {
  439.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects at least 1 parameter", E_USER_WARNING);
  440.                 return false;
  441.                 }
  442.  
  443.         $mode = $this->_defaultMode;
  444.  
  445.         $args = func_get_args();
  446.  
  447.         $rawQuery = array_shift($args);
  448.  
  449.         if (!is_string($rawQuery))
  450.                 {
  451.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be string, " . gettype($rawQuery) . " given", E_USER_WARNING);
  452.                 return false;
  453.                 }
  454.  
  455.         if (!$this->opened())
  456.                 {
  457.                 trigger_error('Not connected to MySQL Server', $this->_sqlErrorLevel);
  458.                 return false;
  459.                 }
  460.  
  461.         if ($numArgs > 1)
  462.                 {
  463.                 $argMode = array_pop($args);
  464.  
  465.                 if (!$this->_is_valid_mode($argMode))
  466.                         { array_push($args, $argMode); }
  467.                 else
  468.                         { $mode = $argMode; }
  469.  
  470.                 if (count($args) > 0)
  471.                         {
  472.                         if ($this->_autoEscape)
  473.                                 foreach ($args as $key => $string)
  474.                                         {
  475.                                         if (is_scalar($string) || is_null($string))
  476.                                                 $args[$key] = $this->escape($string);
  477.                                         else
  478.                                                 {
  479.                                                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter " . ($key + 1) . " to be NULL or scalar, " . gettype($string) . " given", E_USER_WARNING);
  480.                                                 return false;
  481.                                                 }
  482.                                         }
  483.  
  484.                         $query = vsprintf($rawQuery, $args);
  485.                         }
  486.                 else
  487.                         $query = $rawQuery;
  488.                 }
  489.         else
  490.                 $query = $rawQuery;
  491.  
  492.         $resultSet = @mysql_query($query, $this->_conn);
  493.  
  494.         if ($resultSet === FALSE)
  495.                 {
  496.                 $this->_sql_error($query);
  497.                 return false;
  498.                 }
  499.         else
  500.                 {
  501.                 if ($mode == MySQL_MODE_ALL)
  502.                         {
  503.                         $rows=array();
  504.  
  505.                         if (@mysql_num_rows($resultSet))
  506.                                 while ($row = mysql_fetch_array($resultSet))
  507.                                         $rows[] = $row;
  508.  
  509.                         @mysql_free_result($resultSet);
  510.  
  511.                         return $rows;
  512.                         }
  513.                 elseif ($mode == MySQL_MODE_ONE)
  514.                         {
  515.                         $row = null;
  516.  
  517.                         if (@mysql_num_rows($resultSet))
  518.                                 $row = mysql_fetch_array($resultSet);
  519.  
  520.                         @mysql_free_result($resultSet);
  521.  
  522.                         return $row;
  523.                         }
  524.                 else
  525.                         { return $resultSet; }
  526.                 }
  527.         }
  528.  
  529.     function seek($resultSet = NULL, $row = NULL)
  530.         {
  531.         if (is_bool($resultSet))
  532.                 { return false; }
  533.         elseif (!(is_resource($resultSet) && get_resource_type($resultSet) == 'mysql result'))
  534.                 {
  535.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be resource of type (mysql result), " . gettype($resultSet) . " given", E_USER_WARNING);
  536.                 return false;
  537.                 }
  538.         elseif (!is_int($row))
  539.                 {
  540.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 2 to be integer, " . gettype($row) . " given", E_USER_WARNING);
  541.                 return false;
  542.                 }
  543.         else
  544.                 { return@mysql_data_seek($resultSet, $row); }
  545.         }
  546.  
  547.     // +------------------------------------------------------------------+
  548.     // | Public Methods - Helper And Security Functions                   |
  549.     // +------------------------------------------------------------------+
  550.  
  551.     function get_rights($location = '*')
  552.         {
  553.         if (!is_string($location))
  554.                 {
  555.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be string, " . gettype($location) . " given", E_USER_WARNING);
  556.                 return false;
  557.                 }
  558.  
  559.         $locationArray = explode('.', $location);
  560.  
  561.         if (count($locationArray) == 1)
  562.                 {
  563.                 if (is_null($this->_currentDb))
  564.                         $database = '*';
  565.                 else
  566.                         $database = $this->_currentDb;
  567.  
  568.                 $table = $locationArray[0];
  569.                 }
  570.         else
  571.                 {
  572.                 $database = $locationArray[0];
  573.                 $table = $locationArray[1];
  574.                 }
  575.  
  576.         $rights=Array();
  577.  
  578.         $results = $this->query('SHOW GRANTS;', MySQL_MODE_ALL);
  579.  
  580.         if ($results === false)
  581.                 { return false; }
  582.  
  583.         foreach ($results AS $row)
  584.                 {
  585.                 $stmt = $row[0];
  586.                 $matches=Array();
  587.                 preg_match('/GRANT ([\s\S]*) ON ([\s\S]*)[.]([\s\S]*) TO [\s\S]*/', $stmt, $matches);
  588.                 $matches[2] = str_replace('`', '', $matches[2]);
  589.                 $matches[3] = str_replace('`', '', $matches[3]);
  590.  
  591.                 if ($matches[2] == '*' && $matches[3] == '*')
  592.                         {
  593.                         $thoseMatches = explode(',', strtoupper($matches[1]));
  594.  
  595.                         if (strpos(strtoupper($stmt), "WITH GRANT OPTION") !== FALSE)
  596.                                 $thoseMatches[] = "GRANT";
  597.  
  598.                         $rights = array_merge($thoseMatches, $rights);
  599.                         }
  600.                 elseif ($database == '*' && $table != '*' && $matches[2] == '*' && $matches[3] != '*')
  601.                         {
  602.                         if ($this->_match_wildcard($table, $matches[3]))
  603.                                 {
  604.                                 $thoseMatches = explode(',', strtoupper($matches[1]));
  605.  
  606.                                 if (strpos(strtoupper($stmt), "WITH GRANT OPTION") !== FALSE)
  607.                                         $thoseMatches[] = "GRANT";
  608.  
  609.                                 $rights = array_merge($thoseMatches, $rights);
  610.                                 }
  611.                         }
  612.                 elseif ($database != '*' && $table == '*' && $matches[2] != '*' && $matches[3] == '*')
  613.                         {
  614.                         if ($this->_match_wildcard($database, $matches[2]))
  615.                                 {
  616.                                 $thoseMatches = explode(',', strtoupper($matches[1]));
  617.  
  618.                                 if (strpos(strtoupper($stmt), "WITH GRANT OPTION") !== FALSE)
  619.                                         $thoseMatches[] = "GRANT";
  620.  
  621.                                 $rights = array_merge($thoseMatches, $rights);
  622.                                 }
  623.                         }
  624.                 elseif ($database != '*' && $table != '*')
  625.                         {
  626.                         if (($this->_match_wildcard($database, $matches[2]) || $matches[2] == '*') && ($this->_match_wildcard($table, $matches[3]) || $matches[3] == '*'))
  627.                                 {
  628.                                 $thoseMatches = explode(',', strtoupper($matches[1]));
  629.  
  630.                                 if (strpos(strtoupper($stmt), "WITH GRANT OPTION") !== FALSE)
  631.                                         $thoseMatches[] = "GRANT";
  632.  
  633.                                 $rights = array_merge($thoseMatches, $rights);
  634.                                 }
  635.                         }
  636.                 }
  637.  
  638.         foreach ($rights as $key => $value)
  639.                 {
  640.                 $rights[$key] = strtoupper($value);
  641.                 $rights[$key] = trim($rights[$key]);
  642.                 }
  643.  
  644.         $rights = array_unique($rights);
  645.         sort($rights);
  646.  
  647.         return $rights;
  648.         }
  649.  
  650.     function escape($string)
  651.         {
  652.         if (!(is_scalar($string) || is_null($string)))
  653.                 {
  654.                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() expects parameter 1 to be scalar, " . gettype($row) . " given", E_USER_WARNING);
  655.                 return false;
  656.                 }
  657.         elseif ($this->opened())
  658.                 { return@mysql_real_escape_string($string, $this->_conn); }
  659.         else
  660.                 { return@mysql_real_escape_string($string); }
  661.         }
  662.  
  663.     // +------------------------------------------------------------------+
  664.     // | Public Methods - Backwards Compatibility (DO NOT USE)            |
  665.     // +------------------------------------------------------------------+
  666.  
  667.     function affectedRows($result = null)
  668.         {
  669.         $return = $this->count_affected($result);
  670.         return $return;
  671.         }
  672.  
  673.     function auto_escape($autoEscape = null)
  674.         { $this->use_auto_escape($autoEscape); }
  675.  
  676.     function connected()
  677.         { return $this->opened(); }
  678.  
  679.     function dataSeek($result = null, $row = null)
  680.         {
  681.         $return = $this->seek($result, $row);
  682.         return $return;
  683.         }
  684.  
  685.     function dies($strictErrors = null)
  686.         { $this->use_strict_errors($strictErrors); }
  687.  
  688.     function escape_string($string = null)
  689.         {
  690.         $return = $this->escape($string);
  691.         return $return;
  692.         }
  693.  
  694.     function fetchArray($result = null)
  695.         {
  696.         $return = $this->fetch($result);
  697.         return $return;
  698.         }
  699.  
  700.     function getLastError()
  701.         { return $this->get_last_error(); }
  702.  
  703.     function numRows($result = null)
  704.         {
  705.         $return = $this->count($result);
  706.         return $return;
  707.         }
  708.  
  709.     function setDefaultMode($mode = null)
  710.         { $this->set_mode($mode); }
  711.  
  712.     function getRights($location = '*')
  713.         {
  714.         $return = $this->get_rights($location);
  715.         return $return;
  716.         }
  717.     }
  718. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement