Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. <?php
  2.  
  3. class dblib_mysql
  4. {
  5.     /* --    --    --    --    --    --    --    --    --    --    -- */
  6.     /* ATTRIBUTES                                                     */
  7.     /* --    --    --    --    --    --    --    --    --    --    -- */
  8.  
  9.     var $connectionID;
  10.     var $rows;
  11.     var $dbname;
  12.     var $dbuser;
  13.     var $dbpass;
  14.     var $dbhost;
  15.  
  16.     /* --    --    --    --    --    --    --    --    --    --    -- */
  17.     /* CONSTRUCTOR                                                    */
  18.     /* --    --    --    --    --    --    --    --    --    --    -- */
  19.  
  20.     function dblib_mysql ( $dbname, $dbuser, $dbpass, $dbhost )
  21.     {
  22.         $this -> dbname = $dbname;
  23.         $this -> dbuser = $dbuser;
  24.         $this -> dbpass = $dbpass;
  25.         $this -> dbhost = $dbhost;
  26.     }
  27.  
  28.     /* --    --    --    --    --    --    --    --    --    --    -- */
  29.     /* LOG ERROR                                                      */
  30.     /* --    --    --    --    --    --    --    --    --    --    -- */
  31.  
  32.     function logError ( $theString )
  33.     {
  34.         $error = mysql_errno () . " : " . mysql_error ();
  35.         generateLog ( "$error | $theString" );
  36.         exit ( 1 );
  37.     }
  38.  
  39.     /* --    --    --    --    --    --    --    --    --    --    -- */
  40.     /* OPEN A CONNECTION TO MYSQL DB                                  */
  41.     /* --    --    --    --    --    --    --    --    --    --    -- */
  42.  
  43.     function openDB ()
  44.     {
  45.         if ( !isset ( $GLOBALS [ 'openeddb' ] ) )
  46.         {
  47.             $this -> connectionID = mysql_connect ( $this -> dbhost, $this -> dbuser, $this -> dbpass );
  48.  
  49.             if ( !$this -> connectionID )
  50.                 $this->logError ( "Error openDB 1" );
  51.         }
  52.         else
  53.         {
  54.             $this -> connectionID = $GLOBALS [ 'openeddb' ];
  55.         }
  56.  
  57.         generateLog ( "BD = " . $this -> dbname );
  58.  
  59.         $result = mysql_select_db ( $this -> dbname, $this -> connectionID );
  60.         mysql_query("SET NAMES utf8");
  61.  
  62.         if ( !$result )
  63.             $this->logError ( "Error openDB 2" );
  64.     }
  65.  
  66.     /* --    --    --    --    --    --    --    --    --    --    -- */
  67.     /* CLOSE A CONNECTION TO MYSQL DB                                 */
  68.     /* --    --    --    --    --    --    --    --    --    --    -- */
  69.  
  70.     function closeDB ()
  71.     {
  72.         mysql_close ( $this -> connectionID );
  73.     }
  74.  
  75.     /* --    --    --    --    --    --    --    --    --    --    -- */
  76.     /* RUN A QUERY                                                    */
  77.     /* --    --    --    --    --    --    --    --    --    --    -- */
  78.  
  79.     function runQuery ( $query )
  80.     {
  81.         $this -> rows = mysql_query ( $query, $this -> connectionID );
  82.  
  83.         if ( !$this -> rows )
  84.             $this->logError ( "Error runQuery [ $query ]" );
  85.     }
  86.  
  87.     /* --    --    --    --    --    --    --    --    --    --    -- */
  88.     /* GET ROWS NUMBER                                                */
  89.     /* --    --    --    --    --    --    --    --    --    --    -- */
  90.  
  91.     function getRowsNumber ()
  92.     {
  93.         return ( mysql_num_rows ( $this -> rows ) );
  94.     }
  95.  
  96.     /* --    --    --    --    --    --    --    --    --    --    -- */
  97.     /* FREE ROWS                                                      */
  98.     /* --    --    --    --    --    --    --    --    --    --    -- */
  99.  
  100.     function freeRows ()
  101.     {
  102.         mysql_free_result ( $this -> rows );
  103.     }
  104.  
  105.     /* --    --    --    --    --    --    --    --    --    --    -- */
  106.     /* GET ROW                                                        */
  107.     /* --    --    --    --    --    --    --    --    --    --    -- */
  108.  
  109.     function getRow ()
  110.     {
  111.         return ( mysql_fetch_array ( $this -> rows, MYSQL_BOTH ) );
  112.     }
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement