Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////Antipin Anton Aleksandrovich////////////////////////////
- ////////////////////////e-mail: suppor@megax.ru/////////////////////////////////
- ///////////////////////////////Copyright 2006///////////////////////////////////
- define ("HOST","localhost", true);
- define ("LOGIN", "root", true);
- define ("PASS", "123456", true);
- define ("OPTOS", "optos", true);
- class my_SQL
- {
- var $db_host;
- var $db_username;
- var $db_pass;
- var $db_name;
- var $massive=array();
- var $count_db=0;
- var $no_error;
- var $error_str;
- var $link;
- var $id;
- function my_SQL($bdname)
- {
- $this->db_name=$bdname;
- $this->db_host=HOST;
- $this->db_username=LOGIN;
- $this->db_pass=PASS;
- $this->no_error=true;
- }
- function destructor()
- {
- $this->massive=0;
- unset($this->db_host);
- unset($this->db_username);
- unset($this->db_pass);
- unset($this->db_name);
- unset($this->massive);
- unset($this->count_db);
- unset($this->link);
- unset($this->id);
- unset($this->no_error);
- unset($this->error_str);
- unset($this);
- }
- function db_open()
- {
- if (!($this->link=mysql_pconnect($this->db_host,$this->db_username,$this->db_pass)))
- {
- printf("Ошибка при соединении с MySQL !\n");
- exit();
- }
- if (!mysql_select_db($this->db_name, $this->link))
- {
- printf("Ошибка базы данных !");
- exit();
- }
- }
- function KillChars(&$str)
- {
- $badChars=array("select", "drop", ";", "--", "insert", "'", "update", "delete");
- for($i=0; $i<count($badChars); $i++)
- {
- $str=str_replace($badChars[$i], "", $str);
- }
- unset($badChars);
- }
- function del_html($str)
- {
- return (trim(strip_tags($str)));
- }
- function add_shl($str)
- {
- if(!isset($str))
- return ("NULL");
- if(function_exists("mysql_real_escape_string"))
- return ("'". mysql_real_escape_string($str)."'");
- if(function_exists("mysql_escape_string"))
- return ("'". mysql_escape_string($str)."'");
- return("'" . addslashes($str) . "'");
- }
- function strip_shl($value)
- {
- if(!is_array($value))
- $value=stripslashes($value);
- else
- {
- reset($value);
- while (list($k,$v)=each($value))
- $value[$k]=strip_shl($v);
- }
- return ($value);
- }
- function print_parameters()
- {
- print "
- ".$this->db_host."<br>
- ".$this->db_username."<br>
- ".$this->db_pass."<br>
- ".$this->db_name."<br>";
- }
- function existing_data($dat)
- {
- my_SQL::db_open();
- $dat=my_SQL::del_html($dat);
- if(!$dd=@mysql_query($dat))
- {
- $this->no_error=false;
- $this->error_str="Ошибка базы данных №".__LINE__;
- }
- else
- {
- $this->count_db=@mysql_num_rows($dd);
- $this->no_error=true;
- }
- }
- function inserter($str)
- {
- my_SQL::db_open();
- $str=my_SQL::del_html($str);
- if(!mysql_query($str))
- {
- $this->no_error=false;
- print "Ошибка базы данных № ";
- print __LINE__;
- print mysql_error($this->link);
- }
- else
- {
- $this->id=mysql_insert_id();
- }
- }
- function AllParam_query($query_is)
- {
- my_SQL::db_open();
- $query_is=my_SQL::del_html($query_is);
- //$query_is=my_SQL::add_shl($query_is);
- if(!mysql_query($query_is))
- {
- $this->no_error=false;
- $this->error_str="Ошибка базы данных № ".__LINE__;
- $this->error_str.=" ".mysql_error($this->link);
- }
- }
- function count_all($table, $order_by)
- {
- my_SQL::db_open();
- $table=my_SQL::del_html($table);
- $str="select count(*) as count from ".$table." order by ".$order_by."";
- if(($sg=@mysql_query($str))>0)
- {
- $val=@mysql_fetch_array($sg);
- $this->no_error=true;
- return $val['count'];
- }
- else
- {
- $this->no_error=false;
- $this->error_str="Ошибка базы данных № ".__LINE__;
- }
- }
- function GetAssoc($query_is)
- {
- my_SQL::db_open();
- $query_is=$this->del_html($query_is);
- if(($sg=@mysql_query($query_is))>0)
- {
- $this->no_error=true;
- $this->count_db=@mysql_num_rows($sg);
- for($i=0; $i<$this->count_db; $i++)
- {
- $val=@mysql_fetch_array($sg,MYSQL_ASSOC);
- $this->massive[$i]=$val;
- }
- }
- else
- {
- $this->no_error=false;
- print "Ошибка базы данных № ".mysql_error($this->link);
- print __LINE__;
- }
- return $this->massive;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment