Advertisement
Guest User

ConnectDB

a guest
Apr 12th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.98 KB | None | 0 0
  1. <?php
  2. //error_reporting(E_ALL);
  3. error_reporting(0);
  4. ini_set('display_errors', '1');
  5.  
  6.  
  7. class Record
  8. {
  9.     var $RowsCount=0;
  10.     var $Values= array(0 => array(0 => ""));
  11.     var $FieldsCount=0;
  12.     var $FieldNames=array();
  13.  
  14. }
  15.  
  16. class MYSQL
  17. {
  18.       var  $host;
  19.       var  $dbname;
  20.       var  $username;
  21.       var  $password;
  22.  
  23.        function MYSQL()
  24.       {
  25.        
  26.         $this->host = "localhost";
  27.         $this->dbname = "ilasro_maindb";
  28.         $this->username = "ilasro_andrei";
  29.         $this->password = "^iLas.r0$461";
  30.        
  31.         /*
  32.           $this->host = "localhost";
  33.           $this->dbname = "u420762715_ilas";
  34.           $this->username = "u420762715_user";
  35.           $this->password = "^iLas.r0$";
  36.          
  37.         $this->host="localhost";
  38.         $this->dbname="ilasro_ilas";
  39.         $this->username="ilasro";
  40.         $this->password="kata&lystea6";*/
  41.         //$this->password="G56FVEr5nQen6P4X";
  42.                
  43.       }
  44.  
  45.       function __destruct()
  46.       {}
  47.  
  48.  
  49.       function execQuery($query)
  50.       {
  51.            
  52.             // Connecting to server
  53.            
  54.             $rd=new Record();
  55.             $link = mysql_connect($this->host , $this->username , $this->password) or die('Could not connect: ' . mysql_error());
  56.            
  57.             //Selecting database
  58.             mysql_select_db($this->dbname) or die('Could not select database');
  59.            
  60.            
  61.             /****************************
  62.             GET the Field Names
  63.             ********************************/
  64.            
  65.             $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  66.             $row=mysql_fetch_array($result, MYSQL_ASSOC);
  67.            
  68.             $fieldsCount=count($row);
  69.            
  70.             if($fieldsCount>1)
  71.               {
  72.                 for($j=0;$j<$fieldsCount;$j++)
  73.                 {
  74.                      
  75.                      $rd->FieldNames[$j]=key($row);
  76.                      next($row);
  77.                    
  78.  
  79.                 }
  80.            
  81.  
  82.               }
  83.            
  84.             mysql_free_result($result);
  85.            
  86.             /****************************
  87.             GET the Field Values
  88.             ********************************/
  89.  
  90.             $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  91.            
  92.             $rowindex=0;
  93.            
  94.  
  95.             while ($rd->Values[$rowindex] = mysql_fetch_array($result, MYSQL_NUM))
  96.             {
  97.                  $rowindex=$rowindex+1;
  98.                
  99.             }
  100.            
  101.            
  102.             $rd->RowsCount=$rowindex;
  103.             $rd->FieldsCount=$fieldsCount;
  104.  
  105.        
  106.  
  107.             // Free resultset
  108.             mysql_free_result($result);
  109.  
  110.             // Closing connection
  111.             mysql_close($link);
  112.  
  113.             return $rd;
  114.  
  115.      }     
  116.  
  117.  
  118.      function execStatement($query)
  119.       {
  120.            
  121.             // Connecting to server
  122.            
  123.            
  124.             $link = mysql_connect($this->host , $this->username , $this->password) or die('Could not connect: ' . mysql_error());
  125.            
  126.             //Selecting database
  127.             mysql_select_db($this->dbname) or die('Could not select database');
  128.            
  129.             $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  130.            
  131.            
  132.             // Closing connection
  133.             mysql_close($link);
  134.  
  135.             return 1;
  136.  
  137.      }     
  138. }
  139.  
  140. function SafeStr($str)
  141. {
  142.     $str1 = str_replace("'","`",$str);
  143.     $str1 = mysql_real_escape_string($str);
  144.     return $str1;
  145. }
  146.  
  147. function txtTruncate($text, $limit, $break=".", $pad="...")
  148. {
  149.     $text = $text." ";
  150.     $text = substr($text,0,$limit);
  151.     $text = substr($text,0,strrpos($text,' '));
  152.     $text = $text."...";
  153.     return $text;
  154. }
  155. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement