Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SmartSQL {
- # Constructure
- function SmartSQL($host,$username,$password,$db,$type,$report,$email,$sender) {
- $this->host = $host;
- $this->username = $username;
- $this->password = $password;
- $this->db = $db;
- $this->type = $type;
- $this->report = $report;
- $this->email = $email;
- $this->sender = $sender;
- }
- # End Constructure
- # Connect to DB
- function sql_connect() {
- if ($this->type == "mysql") {
- $this->connect = @mysql_connect($this->host,$this->username,$this->password) or die($this->error_msg("Error with connect", "$this->username, $this->password"));
- }
- elseif ($this->type == "mssql") {
- $this->connect = @mssql_connect($this->host,$this->username,$this->password) or die($this->error_msg("Error with connect", "$this->username, $this->password"));
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- }
- # End connect function
- # Select DB
- function sql_selectdb() {
- if ($this->type == "mysql") {
- $this->select = @mysql_select_db($this->db) or die($this->error_msg("Error with select database", $this->db));
- }
- elseif ($this->type == "mssql") {
- $this->select = @mssql_select_db($this->db) or die($this->error_msg("Error with select database",$this->db));
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- }
- # End select function
- # Close connect
- function sql_close() {
- if ($this->type == "mysql") {
- $this->close = @mysql_close() or die($this->error_msg("Error with close connect",$this->db) );
- }
- elseif ($this->type == "mssql") {
- $this->close = @mssql_close() or die($this->error_msg("Error with close connect",$this->db));
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- }
- # End close function
- # Fetch info
- function sql_fetch_array($query) {
- if ($this->type == "mysql") {
- $out = @mysql_fetch_array($query);
- }
- elseif ($this->type == "mssql") {
- $out = @mssql_fetch_array($query);
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- return $out;
- }
- # End fetch function
- # Query DB
- function sql_query($query) {
- if ($this->type == "mysql") {
- $result = @mysql_query($query) or die($this->error_msg("Error with query", $query));
- }
- elseif ($this->type == "mssql") {
- $result = @mssql_query($query) or die($this->error_msg("Error with query", $query));
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- return $result;
- }
- # End Query function
- # Get records number
- function sql_rows_num($query) {
- if ($this->type == "mysql") {
- $out = @mysql_num_rows($query);
- }
- elseif ($this->type == "mssql") {
- $out = @mssql_num_rows($query);
- }
- elseif ($this->type != "mysql" or $this->type != "mssql") {
- $this->style();
- echo '<div align="center">MySQL or MsSQL only !</div>';
- }
- return $out;
- }
- # End records number function
- ## Error functions
- function error_msg($msg, $query) {
- if ($this->type == "mysql") {
- $error_no = mysql_errno();
- $error_msg = mysql_error();
- if ($this->report == 1) {
- $FROM = $this->sender;
- $subject = "Database Error !!";
- $masg .= '<br>';
- $masg .= $msg;
- $masg .= "<br>";
- $masg .= "Error Number :" . $error_no;
- $masg .= '<br>';
- $masg .= "Query :" . $query;
- $masg .= '<br>';
- $masg .= "Error Message :" . $error_msg;
- $hedr = "Content-Type: text/html; charset=iso-8859-1\n";
- $hedr .= "From:"."$FROM\n";
- @mail($this->email,$subject,$masg,$hedr);
- }
- }
- elseif ($this->type = "mssql") {
- if ($this->report == 1) {
- $FROM = $this->sender;
- $subject = "datadase error !!";
- $masg .= '<br>';
- $masg .= $msg;
- $masg .= "<br>";
- $masg .= '<br>';
- $masg .= "Query :" . $query;
- $masg .= "Error Message :" . $error_msg;
- $hedr = "Content-Type: text/html; charset=iso-8859-1\n";
- $hedr .= "From:"."$FROM\n";
- @mail($this->email,$subject,$masg,$hedr);
- }
- }
- $this->style();
- echo "<html><head><title>database error</title><body>";
- echo '<div align="center">';
- echo "sorry we have problem with database : ";
- #echo '<br>';
- echo $msg;
- echo '<br>';
- echo $error_msg;
- echo '<br>';
- echo '</div>';
- exit();
- }
- function style() {
- echo "<style>BODY{FONT-FAMILY:tahoma;FONT-SIZE:12px;}</style>";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment