Guest User

Untitled

a guest
Jul 20th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. ////////////////////////Antipin Anton Aleksandrovich////////////////////////////
  4. ////////////////////////e-mail: suppor@megax.ru/////////////////////////////////
  5. ///////////////////////////////Copyright 2006///////////////////////////////////
  6.  
  7. define ("HOST","localhost", true);
  8. define ("LOGIN", "root", true);
  9. define ("PASS", "123456", true);
  10. define ("OPTOS", "optos", true);
  11.  
  12. class my_SQL
  13. {
  14. var $db_host;
  15. var $db_username;
  16. var $db_pass;
  17. var $db_name;
  18. var $massive=array();
  19. var $count_db=0;
  20. var $no_error;
  21. var $error_str;
  22. var $link;
  23. var $id;
  24. function my_SQL($bdname)
  25. {
  26. $this->db_name=$bdname;
  27. $this->db_host=HOST;
  28. $this->db_username=LOGIN;
  29. $this->db_pass=PASS;
  30. $this->no_error=true;
  31. }
  32. function destructor()
  33. {
  34. $this->massive=0;
  35. unset($this->db_host);
  36. unset($this->db_username);
  37. unset($this->db_pass);
  38. unset($this->db_name);
  39. unset($this->massive);
  40. unset($this->count_db);
  41. unset($this->link);
  42. unset($this->id);
  43. unset($this->no_error);
  44. unset($this->error_str);
  45. unset($this);
  46. }
  47. function db_open()
  48. {
  49. if (!($this->link=mysql_pconnect($this->db_host,$this->db_username,$this->db_pass)))
  50. {
  51. printf("Ошибка при соединении с MySQL !\n");
  52. exit();
  53. }
  54. if (!mysql_select_db($this->db_name, $this->link))
  55. {
  56. printf("Ошибка базы данных !");
  57. exit();
  58. }
  59. }
  60. function KillChars(&$str)
  61. {
  62. $badChars=array("select", "drop", ";", "--", "insert", "'", "update", "delete");
  63. for($i=0; $i<count($badChars); $i++)
  64. {
  65. $str=str_replace($badChars[$i], "", $str);
  66. }
  67. unset($badChars);
  68. }
  69. function del_html($str)
  70. {
  71. return (trim(strip_tags($str)));
  72. }
  73. function add_shl($str)
  74. {
  75. if(!isset($str))
  76. return ("NULL");
  77. if(function_exists("mysql_real_escape_string"))
  78. return ("'". mysql_real_escape_string($str)."'");
  79. if(function_exists("mysql_escape_string"))
  80. return ("'". mysql_escape_string($str)."'");
  81. return("'" . addslashes($str) . "'");
  82. }
  83. function strip_shl($value)
  84. {
  85. if(!is_array($value))
  86. $value=stripslashes($value);
  87. else
  88. {
  89. reset($value);
  90. while (list($k,$v)=each($value))
  91. $value[$k]=strip_shl($v);
  92. }
  93. return ($value);
  94. }
  95. function print_parameters()
  96. {
  97. print "
  98. ".$this->db_host."<br>
  99. ".$this->db_username."<br>
  100. ".$this->db_pass."<br>
  101. ".$this->db_name."<br>";
  102. }
  103. function existing_data($dat)
  104. {
  105. my_SQL::db_open();
  106. $dat=my_SQL::del_html($dat);
  107. if(!$dd=@mysql_query($dat))
  108. {
  109. $this->no_error=false;
  110. $this->error_str="Ошибка базы данных №".__LINE__;
  111. }
  112. else
  113. {
  114. $this->count_db=@mysql_num_rows($dd);
  115. $this->no_error=true;
  116. }
  117. }
  118. function inserter($str)
  119. {
  120. my_SQL::db_open();
  121. $str=my_SQL::del_html($str);
  122. if(!mysql_query($str))
  123. {
  124. $this->no_error=false;
  125. print "Ошибка базы данных № ";
  126. print __LINE__;
  127. print mysql_error($this->link);
  128. }
  129. else
  130. {
  131. $this->id=mysql_insert_id();
  132. }
  133.  
  134. }
  135. function AllParam_query($query_is)
  136. {
  137. my_SQL::db_open();
  138. $query_is=my_SQL::del_html($query_is);
  139. //$query_is=my_SQL::add_shl($query_is);
  140. if(!mysql_query($query_is))
  141. {
  142. $this->no_error=false;
  143. $this->error_str="Ошибка базы данных № ".__LINE__;
  144. $this->error_str.=" ".mysql_error($this->link);
  145. }
  146. }
  147. function count_all($table, $order_by)
  148. {
  149. my_SQL::db_open();
  150. $table=my_SQL::del_html($table);
  151. $str="select count(*) as count from ".$table." order by ".$order_by."";
  152. if(($sg=@mysql_query($str))>0)
  153. {
  154. $val=@mysql_fetch_array($sg);
  155. $this->no_error=true;
  156. return $val['count'];
  157. }
  158. else
  159. {
  160. $this->no_error=false;
  161. $this->error_str="Ошибка базы данных № ".__LINE__;
  162. }
  163. }
  164. function GetAssoc($query_is)
  165. {
  166. my_SQL::db_open();
  167. $query_is=$this->del_html($query_is);
  168. if(($sg=@mysql_query($query_is))>0)
  169. {
  170. $this->no_error=true;
  171. $this->count_db=@mysql_num_rows($sg);
  172. for($i=0; $i<$this->count_db; $i++)
  173. {
  174. $val=@mysql_fetch_array($sg,MYSQL_ASSOC);
  175. $this->massive[$i]=$val;
  176. }
  177. }
  178. else
  179. {
  180. $this->no_error=false;
  181. print "Ошибка базы данных № ".mysql_error($this->link);
  182. print __LINE__;
  183. }
  184. return $this->massive;
  185. }
  186. }
  187. ?>
Add Comment
Please, Sign In to add comment