Guest User

Untitled

a guest
Jan 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. <?php
  2. class SmartSQL {
  3.  
  4. # Constructure
  5. function SmartSQL($host,$username,$password,$db,$type,$report,$email,$sender) {
  6. $this->host = $host;
  7. $this->username = $username;
  8. $this->password = $password;
  9. $this->db = $db;
  10. $this->type = $type;
  11. $this->report = $report;
  12. $this->email = $email;
  13. $this->sender = $sender;
  14.  
  15. }
  16. # End Constructure
  17.  
  18. # Connect to DB
  19. function sql_connect() {
  20. if ($this->type == "mysql") {
  21. $this->connect = @mysql_connect($this->host,$this->username,$this->password) or die($this->error_msg("Error with connect", "$this->username, $this->password"));
  22. }
  23. elseif ($this->type == "mssql") {
  24. $this->connect = @mssql_connect($this->host,$this->username,$this->password) or die($this->error_msg("Error with connect", "$this->username, $this->password"));
  25. }
  26. elseif ($this->type != "mysql" or $this->type != "mssql") {
  27. $this->style();
  28. echo '<div align="center">MySQL or MsSQL only !</div>';
  29. }
  30. }
  31. # End connect function
  32.  
  33. # Select DB
  34. function sql_selectdb() {
  35. if ($this->type == "mysql") {
  36. $this->select = @mysql_select_db($this->db) or die($this->error_msg("Error with select database", $this->db));
  37. }
  38. elseif ($this->type == "mssql") {
  39. $this->select = @mssql_select_db($this->db) or die($this->error_msg("Error with select database",$this->db));
  40. }
  41. elseif ($this->type != "mysql" or $this->type != "mssql") {
  42. $this->style();
  43. echo '<div align="center">MySQL or MsSQL only !</div>';
  44. }
  45. }
  46. # End select function
  47.  
  48. # Close connect
  49. function sql_close() {
  50. if ($this->type == "mysql") {
  51. $this->close = @mysql_close() or die($this->error_msg("Error with close connect",$this->db) );
  52. }
  53. elseif ($this->type == "mssql") {
  54. $this->close = @mssql_close() or die($this->error_msg("Error with close connect",$this->db));
  55. }
  56. elseif ($this->type != "mysql" or $this->type != "mssql") {
  57. $this->style();
  58. echo '<div align="center">MySQL or MsSQL only !</div>';
  59. }
  60. }
  61. # End close function
  62.  
  63. # Fetch info
  64. function sql_fetch_array($query) {
  65. if ($this->type == "mysql") {
  66. $out = @mysql_fetch_array($query);
  67. }
  68. elseif ($this->type == "mssql") {
  69. $out = @mssql_fetch_array($query);
  70. }
  71. elseif ($this->type != "mysql" or $this->type != "mssql") {
  72. $this->style();
  73. echo '<div align="center">MySQL or MsSQL only !</div>';
  74. }
  75. return $out;
  76. }
  77. # End fetch function
  78.  
  79. # Query DB
  80. function sql_query($query) {
  81. if ($this->type == "mysql") {
  82. $result = @mysql_query($query) or die($this->error_msg("Error with query", $query));
  83. }
  84. elseif ($this->type == "mssql") {
  85. $result = @mssql_query($query) or die($this->error_msg("Error with query", $query));
  86. }
  87. elseif ($this->type != "mysql" or $this->type != "mssql") {
  88. $this->style();
  89. echo '<div align="center">MySQL or MsSQL only !</div>';
  90. }
  91. return $result;
  92. }
  93. # End Query function
  94.  
  95. # Get records number
  96. function sql_rows_num($query) {
  97. if ($this->type == "mysql") {
  98. $out = @mysql_num_rows($query);
  99. }
  100. elseif ($this->type == "mssql") {
  101. $out = @mssql_num_rows($query);
  102. }
  103. elseif ($this->type != "mysql" or $this->type != "mssql") {
  104. $this->style();
  105. echo '<div align="center">MySQL or MsSQL only !</div>';
  106. }
  107. return $out;
  108. }
  109. # End records number function
  110.  
  111. ## Error functions
  112. function error_msg($msg, $query) {
  113. if ($this->type == "mysql") {
  114. $error_no = mysql_errno();
  115. $error_msg = mysql_error();
  116.  
  117. if ($this->report == 1) {
  118. $FROM = $this->sender;
  119. $subject = "Database Error !!";
  120. $masg .= '<br>';
  121. $masg .= $msg;
  122. $masg .= "<br>";
  123. $masg .= "Error Number :" . $error_no;
  124. $masg .= '<br>';
  125. $masg .= "Query :" . $query;
  126. $masg .= '<br>';
  127. $masg .= "Error Message :" . $error_msg;
  128. $hedr = "Content-Type: text/html; charset=iso-8859-1\n";
  129. $hedr .= "From:"."$FROM\n";
  130. @mail($this->email,$subject,$masg,$hedr);
  131. }
  132. }
  133. elseif ($this->type = "mssql") {
  134. if ($this->report == 1) {
  135. $FROM = $this->sender;
  136. $subject = "datadase error !!";
  137. $masg .= '<br>';
  138. $masg .= $msg;
  139. $masg .= "<br>";
  140. $masg .= '<br>';
  141. $masg .= "Query :" . $query;
  142. $masg .= "Error Message :" . $error_msg;
  143. $hedr = "Content-Type: text/html; charset=iso-8859-1\n";
  144. $hedr .= "From:"."$FROM\n";
  145. @mail($this->email,$subject,$masg,$hedr);
  146. }
  147. }
  148.  
  149. $this->style();
  150. echo "<html><head><title>database error</title><body>";
  151. echo '<div align="center">';
  152. echo "sorry we have problem with database : ";
  153. #echo '<br>';
  154. echo $msg;
  155. echo '<br>';
  156. echo $error_msg;
  157. echo '<br>';
  158. echo '</div>';
  159. exit();
  160. }
  161. function style() {
  162. echo "<style>BODY{FONT-FAMILY:tahoma;FONT-SIZE:12px;}</style>";
  163. }
  164. }
  165.  
  166.  
  167. ?>
Add Comment
Please, Sign In to add comment