Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php class msSQL_Core { public $use_cache = false; public $cache_dir = false; p..
Decoded Output download
<?php
class msSQL_Core
{
public $use_cache = false;
public $cache_dir = false;
public $cache_queries = false;
public $cache_timeout = false;
/*
@Database Connection
@param $db
@param $uid
@param $pass
*/
public function __construct($driver, $server, $db, $uid, $pass)
{
try
{
if ($server != 'localhost')
{
if ( !($this->conn = odbc_connect("DRIVER=" . $driver . ";SERVER=" . $server . ";DATABASE=" . $db, $uid, $pass)) )
{
exit("<b>Error:</b> Database connection is failed.<br><b>Message:</b> " . odbc_errormsg());
}
}
elseif ( !($this->conn = odbc_connect($db, $uid, $pass)) )
{
exit("<b>Error:</b> Database connection is failed.<br><b>Message:</b> " . odbc_errormsg());
}
} catch ( exception $error )
{
exit($error->getMessage());
}
}
/*
@Perform ODBC query
@param $var
*/
public function exec_query($var)
{
if ( $var )
{
$this->query = odbc_exec($this->conn, $var) or exit("<b>Error:</b> Query String Failed.<br><b>Message:</b> " . odbc_errormsg());
return $this->query;
}
return false;
}
/*
@If result value is an object, this function called.
@param $var
*/
public function get_object($var)
{
if ( $var )
{
if ( !$this->get_cache($var) )
{
$data = odbc_fetch_object($this->exec_query($var));
$this->store_cache($var, $data);
return $data;
}
return $this->get_cache($var);
}
}
/*
@If result value is an array, this function called.
@@param $var
*/
public function get_array($var)
{
if ( $var )
{
if ( !$this->get_cache($var) )
{
$count = 0;
$data = array();
for ( $res = $this->exec_query($var); $row = @odbc_fetch_array($res); $count++ ) {
$data[ $count ] = $row;
}
$this->store_cache($var, $data);
return $data;
}
return $this->get_cache($var);
}
}
/*
@This function takes precautions against attacks from the outside.
@param $str
*/
public function escape($str)
{
switch ( gettype($str) )
{
case "string":
$str = addslashes(stripslashes($str));
break;
case "boolean":
$str = ($str === false ? 0 : 1);
break;
default:
$str = ($str === null ? "NULL" : $str);
break;
}
return $str;
}
/*
@This function takes precautions against attacks from the outside.
@param $str
*/
public function sqldefender($str)
{
$search = array("/*", "*/", "'");
$replace = array("", "", "");
$str = str_ireplace($search, $replace, $str);
$str = htmlspecialchars($str);
if ( preg_match("@insert|delete|update|replace|truncate|drop|create|exec|select@si", $str) )
{
exit("SQL Injection Detected");
}
switch ( gettype($str) )
{
case "string":
$str = addslashes(stripslashes($str));
break;
case "boolean":
$str = ($str === false ? 0 : 1);
break;
default:
$str = ($str === null ? "NULL" : $str);
break;
}
return $str;
}
/*
@This function works the insert process
@param $table_name
@param $column_names
*/
public function insert($table_name, $column_names)
{
if ( is_array($column_names) )
{
foreach ( $column_names as $rows => $values )
{
$array_rows[] = "" . $rows . "";
$array_values[] = "'" . $values . "'";
}
}
$rows = implode(",", $array_rows);
$values = implode(",", $array_values);
$query = "INSERT INTO " . $table_name . " (" . $rows . ") VALUES (" . $values . ");";
return $this->exec_query($query);
}
/*
@This function works the update process
@param $table_name
@param $column_names
@param $where
*/
public function update($table_name, $column_names, $where = 0)
{
if ( is_array($column_names) )
{
foreach ( $column_names as $rows => $values )
{
$array_rows[] = (string)$rows . " = '" . $values . "'";
}
$rows = implode(",", $array_rows);
if ( 0 < $where )
{
if ( is_array($where) )
{
foreach ( $where as $w_rows => $w_values )
{
$w_arr_rows[] = (string)$w_rows . " = '" . $w_values . "'";
}
$where = implode(" AND ", $w_arr_rows);
}
$update = "UPDATE " . $table_name . " SET " . $rows . " WHERE " . $where;
}
else
{
$update = "UPDATE " . $table_name . " SET " . $rows;
}
$res = $this->exec_query($update);
return $res;
if ( is_resource($res) )
{
return $res;
}
}
}
/**
* This function works the delete process
* @param $table_name
* @param $wheres
*/
public function delete($table_name, $wheres)
{
if ( is_array($wheres) )
{
foreach ( $wheres as $rows => $values )
{
$array_wheres[] = (string)$rows . " = '" . $values . "'";
}
$where = implode(" AND ", $array_wheres);
$query = "DELETE FROM " . $table_name . " WHERE " . $where;
$res = $this->exec_query($query);
if ( is_resource($res) )
{
return $res;
}
}
}
/*
@This function works the debug process
@param $query
*/
public function debug($query)
{
echo "<pre>";
print_r($query);
echo "</pre>";
}
/*
@This function works get the cache query
@param $query
*/
public function get_cache($query)
{
$cache_file = $this->cache_dir . "/" . md5($query) . ".mrx";
if ( $this->use_cache == true && $this->cache_queries == true && file_exists($cache_file) )
{
if ( time() - $this->cache_timeout * 60 < filemtime($cache_file) )
{
$result_cache = file_get_contents($cache_file);
return unserialize($result_cache);
}
unlink($cache_file);
}
}
/*
@This function works store the cache query
@param $query
@param $data
*/
public function store_cache($query, $data)
{
if ( $this->use_cache == true && $this->cache_queries == true )
{
$cache_file = $this->cache_dir . "/" . md5($query) . ".mrx";
ob_start();
$open = fopen($cache_file, "w+");
fwrite($open, serialize($data));
fclose($open);
ob_end_flush();
}
}
public function __desctruct()
{
odbc_free_result();
odbc_close($this->conn);
}
} ?>
Did this file decode correctly?
Original Code
<?php
class msSQL_Core
{
public $use_cache = false;
public $cache_dir = false;
public $cache_queries = false;
public $cache_timeout = false;
/*
@Database Connection
@param $db
@param $uid
@param $pass
*/
public function __construct($driver, $server, $db, $uid, $pass)
{
try
{
if ($server != 'localhost')
{
if ( !($this->conn = odbc_connect("DRIVER=" . $driver . ";SERVER=" . $server . ";DATABASE=" . $db, $uid, $pass)) )
{
exit("<b>Error:</b> Database connection is failed.<br><b>Message:</b> " . odbc_errormsg());
}
}
elseif ( !($this->conn = odbc_connect($db, $uid, $pass)) )
{
exit("<b>Error:</b> Database connection is failed.<br><b>Message:</b> " . odbc_errormsg());
}
} catch ( exception $error )
{
exit($error->getMessage());
}
}
/*
@Perform ODBC query
@param $var
*/
public function exec_query($var)
{
if ( $var )
{
$this->query = odbc_exec($this->conn, $var) or exit("<b>Error:</b> Query String Failed.<br><b>Message:</b> " . odbc_errormsg());
return $this->query;
}
return false;
}
/*
@If result value is an object, this function called.
@param $var
*/
public function get_object($var)
{
if ( $var )
{
if ( !$this->get_cache($var) )
{
$data = odbc_fetch_object($this->exec_query($var));
$this->store_cache($var, $data);
return $data;
}
return $this->get_cache($var);
}
}
/*
@If result value is an array, this function called.
@@param $var
*/
public function get_array($var)
{
if ( $var )
{
if ( !$this->get_cache($var) )
{
$count = 0;
$data = array();
for ( $res = $this->exec_query($var); $row = @odbc_fetch_array($res); $count++ ) {
$data[ $count ] = $row;
}
$this->store_cache($var, $data);
return $data;
}
return $this->get_cache($var);
}
}
/*
@This function takes precautions against attacks from the outside.
@param $str
*/
public function escape($str)
{
switch ( gettype($str) )
{
case "string":
$str = addslashes(stripslashes($str));
break;
case "boolean":
$str = ($str === false ? 0 : 1);
break;
default:
$str = ($str === null ? "NULL" : $str);
break;
}
return $str;
}
/*
@This function takes precautions against attacks from the outside.
@param $str
*/
public function sqldefender($str)
{
$search = array("/*", "*/", "'");
$replace = array("", "", "");
$str = str_ireplace($search, $replace, $str);
$str = htmlspecialchars($str);
if ( preg_match("@insert|delete|update|replace|truncate|drop|create|exec|select@si", $str) )
{
exit("SQL Injection Detected");
}
switch ( gettype($str) )
{
case "string":
$str = addslashes(stripslashes($str));
break;
case "boolean":
$str = ($str === false ? 0 : 1);
break;
default:
$str = ($str === null ? "NULL" : $str);
break;
}
return $str;
}
/*
@This function works the insert process
@param $table_name
@param $column_names
*/
public function insert($table_name, $column_names)
{
if ( is_array($column_names) )
{
foreach ( $column_names as $rows => $values )
{
$array_rows[] = "" . $rows . "";
$array_values[] = "'" . $values . "'";
}
}
$rows = implode(",", $array_rows);
$values = implode(",", $array_values);
$query = "INSERT INTO " . $table_name . " (" . $rows . ") VALUES (" . $values . ");";
return $this->exec_query($query);
}
/*
@This function works the update process
@param $table_name
@param $column_names
@param $where
*/
public function update($table_name, $column_names, $where = 0)
{
if ( is_array($column_names) )
{
foreach ( $column_names as $rows => $values )
{
$array_rows[] = (string)$rows . " = '" . $values . "'";
}
$rows = implode(",", $array_rows);
if ( 0 < $where )
{
if ( is_array($where) )
{
foreach ( $where as $w_rows => $w_values )
{
$w_arr_rows[] = (string)$w_rows . " = '" . $w_values . "'";
}
$where = implode(" AND ", $w_arr_rows);
}
$update = "UPDATE " . $table_name . " SET " . $rows . " WHERE " . $where;
}
else
{
$update = "UPDATE " . $table_name . " SET " . $rows;
}
$res = $this->exec_query($update);
return $res;
if ( is_resource($res) )
{
return $res;
}
}
}
/**
* This function works the delete process
* @param $table_name
* @param $wheres
*/
public function delete($table_name, $wheres)
{
if ( is_array($wheres) )
{
foreach ( $wheres as $rows => $values )
{
$array_wheres[] = (string)$rows . " = '" . $values . "'";
}
$where = implode(" AND ", $array_wheres);
$query = "DELETE FROM " . $table_name . " WHERE " . $where;
$res = $this->exec_query($query);
if ( is_resource($res) )
{
return $res;
}
}
}
/*
@This function works the debug process
@param $query
*/
public function debug($query)
{
echo "<pre>";
print_r($query);
echo "</pre>";
}
/*
@This function works get the cache query
@param $query
*/
public function get_cache($query)
{
$cache_file = $this->cache_dir . "/" . md5($query) . ".mrx";
if ( $this->use_cache == true && $this->cache_queries == true && file_exists($cache_file) )
{
if ( time() - $this->cache_timeout * 60 < filemtime($cache_file) )
{
$result_cache = file_get_contents($cache_file);
return unserialize($result_cache);
}
unlink($cache_file);
}
}
/*
@This function works store the cache query
@param $query
@param $data
*/
public function store_cache($query, $data)
{
if ( $this->use_cache == true && $this->cache_queries == true )
{
$cache_file = $this->cache_dir . "/" . md5($query) . ".mrx";
ob_start();
$open = fopen($cache_file, "w+");
fwrite($open, serialize($data));
fclose($open);
ob_end_flush();
}
}
public function __desctruct()
{
odbc_free_result();
odbc_close($this->conn);
}
}
Function Calls
None |
Stats
MD5 | 9174b6e8ce7c3f2bf652118b6376d104 |
Eval Count | 0 |
Decode Time | 87 ms |