Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class database {
- var $host;
- var $user;
- var $pass;
- var $database;
- var $persistent = 0;
- var $last_query;
- var $result;
- var $connection_id;
- var $num_queries = 0;
- // beallitom az adatbazis csatlakozasi adatait
- function configure($host, $user, $pass, $database, $persistent=0) {
- $this->host = $host;
- $this->user = $user;
- $this->pass = $pass;
- $this->database = $database;
- $this->persistent = $persistent;
- return 1; //Success.
- }
- // csatlakozas az adatbazishoz
- function connect() {
- if (!$this->host) {
- $this->host = "localhost";
- }
- if (!$this->user) {
- $this->user = "root";
- }
- if ($this->persistent) {
- $this->connection_id = mysql_connect($this->host, $this->user, $this->pass) or $this->connection_error();
- } else {
- $this->connection_id = mysql_connect($this->host, $this->user, $this->pass, 1) or $this->connection_error();
- }
- mysql_select_db($this->database, $this->connection_id);
- return $this->connection_id;
- }
- // lecsatlakozas
- function disconnect() {
- if ($this->connection_id) {
- mysql_close($this->connection_id);
- $this->connection_id = 0;
- return 1;
- } else {
- return 0;
- }
- }
- // beillesztes egy adott tablaba
- function insertToTable($tablename, $fields, $values) {
- $fields = implode(',', $fields);
- foreach ($values as &$v) {
- $v = "'$v'";
- }
- $values = implode(',', $values);
- $query = ("INSERT INTO `$tablename` ($fields) VALUES ($values);");
- return mysql_query($query) or die(mysql_error());
- }
- // torles a tablabol
- function deleteFromTable($tablename, $fields, $values) {
- $query = "DELETE FROM `$tablename` WHERE `$fields`=$values";
- return mysql_query($query) or die(mysql_error());
- }
- // adatok felulirasa
- function updateData($tablename, $fields, $values, $id) {
- // kiszedem egy tombbe az erintett mezoket
- $dataFields = explode(" ", $fields);
- // kiszedem egy sztringbe az erintett ertekeket
- $dataValues = explode(" ", $values);
- $i = 0;
- // elkeszitem dinamikusan felulirando mezoket es hozza rendelem a valtozokat
- while ($dataFields[$i]) {
- $updateArray .= ",`$dataFields[$i]` = '$dataValues[$i]'";
- $i++;
- }
- // kiszedem az elso vesszot a sztringbol
- $updateArray = substr($updateArray, 1);
- echo $query;
- $query = "UPDATE `$tablename` SET $updateArray WHERE `id` =$id;";
- echo $query;
- return mysql_query($query) or die(mysql_error());
- }
- // egy string biztonsagossa tetele
- public function filterParameters($array) {
- // Check if the parameter is an array
- if (is_array($array)) {
- // Loop through the initial dimension
- foreach ($array as $key => $value) {
- // Check if any nodes are arrays themselves
- if (is_array($array[$key]))
- // If they are, let the function call itself over that particular node
- $array[$key] = $this->filterParameters($array[$key]);
- // Check if the nodes are strings
- if (is_string($array[$key]))
- // If they are, perform the real escape function over the selected node
- $array[$key] = mysql_real_escape_string($array[$key]);
- }
- }
- // Check if the parameter is a string
- if (is_string($array))
- // If it is, perform a mysql_real_escape_string on the parameter
- $array = mysql_real_escape_string($array);
- // Return the filtered result
- return $array;
- }
- }
Add Comment
Please, Sign In to add comment