Guest User

Untitled

a guest
Oct 29th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.90 KB | None | 0 0
  1. class database {
  2.  
  3.     var $host;
  4.     var $user;
  5.     var $pass;
  6.     var $database;
  7.     var $persistent = 0;
  8.     var $last_query;
  9.     var $result;
  10.     var $connection_id;
  11.     var $num_queries = 0;
  12.  
  13.     // beallitom az adatbazis csatlakozasi adatait
  14.     function configure($host, $user, $pass, $database, $persistent=0) {
  15.         $this->host = $host;
  16.         $this->user = $user;
  17.         $this->pass = $pass;
  18.         $this->database = $database;
  19.         $this->persistent = $persistent;
  20.         return 1; //Success.
  21.     }
  22.  
  23.     // csatlakozas az adatbazishoz
  24.     function connect() {
  25.         if (!$this->host) {
  26.             $this->host = "localhost";
  27.         }
  28.         if (!$this->user) {
  29.             $this->user = "root";
  30.         }
  31.         if ($this->persistent) {
  32.             $this->connection_id = mysql_connect($this->host, $this->user, $this->pass) or $this->connection_error();
  33.         } else {
  34.             $this->connection_id = mysql_connect($this->host, $this->user, $this->pass, 1) or $this->connection_error();
  35.         }
  36.         mysql_select_db($this->database, $this->connection_id);
  37.         return $this->connection_id;
  38.     }
  39.  
  40.     // lecsatlakozas
  41.     function disconnect() {
  42.         if ($this->connection_id) {
  43.             mysql_close($this->connection_id);
  44.             $this->connection_id = 0;
  45.             return 1;
  46.         } else {
  47.             return 0;
  48.         }
  49.     }
  50.  
  51.     // beillesztes egy adott tablaba
  52.     function insertToTable($tablename, $fields, $values) {
  53.         $fields = implode(',', $fields);
  54.         foreach ($values as &$v) {
  55.            $v = "'$v'";
  56.         }
  57.         $values = implode(',', $values);
  58.         $query = ("INSERT INTO  `$tablename` ($fields) VALUES ($values);");
  59.         return mysql_query($query) or die(mysql_error());
  60.     }
  61.  
  62.     // torles a tablabol
  63.     function deleteFromTable($tablename, $fields, $values) {
  64.         $query = "DELETE FROM `$tablename` WHERE `$fields`=$values";
  65.         return mysql_query($query) or die(mysql_error());
  66.     }
  67.  
  68.     // adatok felulirasa
  69.     function updateData($tablename, $fields, $values, $id) {
  70.         // kiszedem egy tombbe az erintett mezoket
  71.         $dataFields = explode(" ", $fields);
  72.         // kiszedem egy sztringbe az erintett ertekeket
  73.         $dataValues = explode(" ", $values);
  74.         $i = 0;
  75.         // elkeszitem dinamikusan felulirando mezoket es hozza rendelem a valtozokat
  76.         while ($dataFields[$i]) {
  77.             $updateArray .= ",`$dataFields[$i]` = '$dataValues[$i]'";
  78.             $i++;
  79.         }
  80.         // kiszedem az elso vesszot a sztringbol
  81.         $updateArray = substr($updateArray, 1);
  82.         echo $query;
  83.         $query = "UPDATE  `$tablename` SET $updateArray WHERE  `id` =$id;";
  84.         echo $query;
  85.         return mysql_query($query) or die(mysql_error());
  86.     }
  87.  
  88.     // egy string biztonsagossa tetele
  89.     public function filterParameters($array) {
  90.  
  91.         // Check if the parameter is an array
  92.         if (is_array($array)) {
  93.             // Loop through the initial dimension
  94.             foreach ($array as $key => $value) {
  95.                 // Check if any nodes are arrays themselves
  96.                 if (is_array($array[$key]))
  97.                 // If they are, let the function call itself over that particular node
  98.                     $array[$key] = $this->filterParameters($array[$key]);
  99.  
  100.                 // Check if the nodes are strings
  101.                 if (is_string($array[$key]))
  102.                 // If they are, perform the real escape function over the selected node
  103.                     $array[$key] = mysql_real_escape_string($array[$key]);
  104.             }
  105.         }
  106.         // Check if the parameter is a string
  107.         if (is_string($array))
  108.         // If it is, perform a  mysql_real_escape_string on the parameter
  109.             $array = mysql_real_escape_string($array);
  110.  
  111.         // Return the filtered result
  112.         return $array;
  113.     }
  114.  
  115. }
Add Comment
Please, Sign In to add comment