Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.25 KB | None | 0 0
  1. <?php
  2. /***************************************************************************
  3.  *                                 mysqli.php
  4.  *                            -------------------
  5.  *   begin                : Saturday, Feb 13, 2001
  6.  *   copyright            : (C) 2001 The phpBB Group
  7.  *   email                : support@phpbb.com
  8.  *
  9.  *   $Id: mysqli.php,v 1.16.2.1 2005/09/18 16:17:20 acydburn Exp $
  10.  *
  11.  ***************************************************************************/
  12.  
  13. /***************************************************************************
  14.  *
  15.  *   This program is free software; you can redistribute it and/or modify
  16.  *   it under the terms of the GNU General Public License as published by
  17.  *   the Free Software Foundation; either version 2 of the License, or
  18.  *   (at your option) any later version.
  19.  *
  20.  ***************************************************************************/
  21.  
  22. if(!defined("SQL_LAYER"))
  23. {
  24.  
  25. define("SQL_LAYER","mysqli");
  26.  
  27. class sql_db
  28. {
  29.  
  30.     var $query_result;
  31.     var $row = array();
  32.     var $rowset = array();
  33.     var $num_queries = 0;
  34.  
  35.     //
  36.     // Constructor
  37.     //
  38.     function sql_db($sqlserver, $sqluser, $sqlpassword, $database)
  39.     {
  40.  
  41.         $this->user = $sqluser;
  42.         $this->password = $sqlpassword;
  43.         $this->server = $sqlserver;
  44.         $this->dbname = $database;
  45.  
  46.         $this->db_connect_id = new mysqli($this->server, $this->user, $this->password, $this->dbname);
  47.  
  48.         if($this->db_connect_id)
  49.         {
  50.         /**
  51.         * установка кодировки соединения
  52.         * на продакшене не использовать, кодировку нужно установить для всего сервера в my.cnf
  53.         */
  54.             mysqli_set_charset ( $this->db_connect_id, 'utf8' );
  55.             if($database != "")
  56.             {
  57.                 $this->dbname = $database;
  58.                 $dbselect = mysqli_select_db($this->db_connect_id, $this->dbname);
  59.                 if(!$dbselect)
  60.                 {
  61.                     mysqli_close($this->db_connect_id);
  62.                     $this->db_connect_id = $dbselect;
  63.                 }
  64.             }
  65.             return $this->db_connect_id;
  66.         }
  67.         else
  68.         {
  69.             return false;
  70.         }
  71.     }
  72.  
  73.     //
  74.     // Other base methods
  75.     //
  76.     function sql_close()
  77.     {
  78.         if($this->db_connect_id)
  79.         {
  80.             if($this->query_result)
  81.             {
  82.                 mysqli_free_result($this->query_result);
  83.             }
  84.             $result = mysqli_close($this->db_connect_id);
  85.             return $result;
  86.         }
  87.         else
  88.         {
  89.             return false;
  90.         }
  91.     }
  92.  
  93.     //
  94.     // Base query method
  95.     //
  96.     function sql_query($query = "", $transaction = FALSE)
  97.     {
  98.         // Remove any pre-existing queries
  99.         unset($this->query_result);
  100.         if($query != "")
  101.         {
  102.             $this->num_queries++;
  103.  
  104.             $this->query_result = mysqli_query($this->db_connect_id, $query);
  105.         }
  106.         if($this->query_result)
  107.         {
  108.             return $this->query_result;
  109.         }
  110.         else
  111.         {
  112.             return ( $transaction == END_TRANSACTION ) ? true : false;
  113.         }
  114.     }
  115.  
  116.     //
  117.     // Other query methods
  118.     //
  119.     function sql_numrows($query_id = 0)
  120.     {
  121.         if(!$query_id)
  122.         {
  123.             $query_id = $this->query_result;
  124.         }
  125.         if($query_id)
  126.         {
  127.             return mysqli_num_rows($query_id);
  128.         }
  129.         else
  130.         {
  131.             return false;
  132.         }
  133.     }
  134.     function sql_affectedrows()
  135.     {
  136.         if($this->db_connect_id)
  137.         {
  138.             $result = mysqli_affected_rows($this->db_connect_id);
  139.             return $result;
  140.         }
  141.         else
  142.         {
  143.             return false;
  144.         }
  145.     }
  146.     function sql_numfields($query_id = 0)
  147.     {
  148.         if(!$query_id)
  149.         {
  150.             $query_id = $this->query_result;
  151.         }
  152.         if($query_id)
  153.         {
  154.             $result = mysqli_num_fields($query_id);
  155.             return $result;
  156.         }
  157.         else
  158.         {
  159.             return false;
  160.         }
  161.     }
  162.     function sql_fieldname($offset, $query_id = 0)
  163.     {
  164.         if(!$query_id)
  165.         {
  166.             $query_id = $this->query_result;
  167.         }
  168.         if($query_id)
  169.         {
  170.             $result = mysqli_field_name($query_id, $offset);
  171.             return $result;
  172.         }
  173.         else
  174.         {
  175.             return false;
  176.         }
  177.     }
  178.     function sql_fieldtype($offset, $query_id = 0)
  179.     {
  180.         if(!$query_id)
  181.         {
  182.             $query_id = $this->query_result;
  183.         }
  184.         if($query_id)
  185.         {
  186.             $result = mysqli_field_type($query_id, $offset);
  187.             return $result;
  188.         }
  189.         else
  190.         {
  191.             return false;
  192.         }
  193.     }
  194.     function sql_fetchrow($query_id = 0)
  195.     {
  196.         if(!$query_id)
  197.         {
  198.             $query_id = $this->query_result;
  199.         }
  200.         if($query_id)
  201.         {
  202.             return $this->query_result->fetch_assoc();
  203.         }
  204.         else
  205.         {
  206.             return false;
  207.         }
  208.     }
  209.     function sql_fetchrowset($query_id = 0)
  210.     {
  211.                 if(!$query_id)
  212.                 {
  213.                         $query_id = $this->query_result;
  214.                 }
  215.                 if($query_id)
  216.                 {
  217.             for ($set = array ();$row = $this->query_result->fetch_assoc();$set[] = $row);
  218.         return $set;
  219.                 }
  220.                 else
  221.                 {
  222.                         return false;
  223.                 }
  224.     }
  225.     function sql_fetchfield($field, $rownum = -1, $query_id = 0)
  226.     {
  227.         if(!$query_id)
  228.         {
  229.             $query_id = $this->query_result;
  230.         }
  231.         if($query_id)
  232.         {
  233.             if($rownum > -1)
  234.             {
  235.                 $result = mysqli_result($query_id, $rownum, $field);
  236.             }
  237.             else
  238.             {
  239.                 if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
  240.                 {
  241.                     if($this->sql_fetchrow())
  242.                     {
  243.                         $result = $this->row[$query_id][$field];
  244.                     }
  245.                 }
  246.                 else
  247.                 {
  248.                     if($this->rowset[$query_id])
  249.                     {
  250.                         $result = $this->rowset[$query_id][0][$field];
  251.                     }
  252.                     else if($this->row[$query_id])
  253.                     {
  254.                         $result = $this->row[$query_id][$field];
  255.                     }
  256.                 }
  257.             }
  258.             return $result;
  259.         }
  260.         else
  261.         {
  262.             return false;
  263.         }
  264.     }
  265.     function sql_rowseek($rownum, $query_id = 0){
  266.         if(!$query_id)
  267.         {
  268.             $query_id = $this->query_result;
  269.         }
  270.         if($query_id)
  271.         {
  272.             $result = mysqli_data_seek($query_id, $rownum);
  273.             return $result;
  274.         }
  275.         else
  276.         {
  277.             return false;
  278.         }
  279.     }
  280.     function sql_nextid(){
  281.         if($this->db_connect_id)
  282.         {
  283.             $result = mysqli_insert_id($this->db_connect_id);
  284.             return $result;
  285.         }
  286.         else
  287.         {
  288.             return false;
  289.         }
  290.     }
  291.     function sql_freeresult($query_id = 0){
  292.         if(!$query_id)
  293.         {
  294.             $query_id = $this->query_result;
  295.         }
  296.  
  297.         if ( $query_id )
  298.         {
  299.             unset($this->row[$query_id]);
  300.             unset($this->rowset[$query_id]);
  301.  
  302.             mysqli_free_result($query_id);
  303.  
  304.             return true;
  305.         }
  306.         else
  307.         {
  308.             return false;
  309.         }
  310.     }
  311.     function sql_error($query_id = 0)
  312.     {
  313.         $result["message"] = mysqli_error($this->db_connect_id);
  314.         $result["code"] = mysqli_errno($this->db_connect_id);
  315.  
  316.         return $result;
  317.     }
  318.  
  319. } // class sql_db
  320.  
  321. } // if ... define
  322.  
  323. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement