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 namespace Swoole\Database; use Swoole; /** * MySQL * * @package SwooleExtend *..
Decoded Output download
<?php
namespace Swoole\Database;
use Swoole;
/**
* MySQL
*
* @package SwooleExtend
* @author Tianfeng.Han
*
*/
class MySQL implements \Swoole\IDatabase
{
public $debug = false;
public $conn = null;
public $config;
const DEFAULT_PORT = 3306;
function __construct($db_config)
{
if (empty($db_config['port']))
{
$db_config['port'] = self::DEFAULT_PORT;
}
$this->config = $db_config;
}
/**
*
*
* @see Swoole.IDatabase::connect()
*/
function connect()
{
$db_config = $this->config;
if (empty($db_config['persistent']))
{
$this->conn = mysql_connect($db_config['host'] . ':' . $db_config['port'],
$db_config['user'],
$db_config['passwd']);
}
else
{
$this->conn = mysql_pconnect($db_config['host'] . ':' . $db_config['port'],
$db_config['user'],
$db_config['passwd']);
}
if (!$this->conn)
{
Swoole\Error::info(__CLASS__." SQL Error", mysql_error($this->conn));
return false;
}
mysql_select_db($db_config['name'], $this->conn) or Swoole\Error::info("SQL Error", mysql_error($this->conn));
if ($db_config['setname'])
{
mysql_query('set names ' . $db_config['charset'], $this->conn) or Swoole\Error::info("SQL Error",
mysql_error($this->conn));
}
return true;
}
function errorMessage($sql)
{
return mysql_error($this->conn) . "<hr />$sql<hr />MySQL Server: {$this->config['host']}:{$this->config['port']}";
}
/**
* SQL
*
* @param string $sql SQL
*
* @return MySQLRecord | false
*/
function query($sql)
{
$res = false;
for ($i = 0; $i < 2; $i++)
{
$res = mysql_query($sql, $this->conn);
if ($res === false)
{
if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013)
{
$r = $this->checkConnection();
if ($r === true)
{
continue;
}
}
\Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
return false;
}
break;
}
if (!$res)
{
Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
return false;
}
if (is_bool($res))
{
return $res;
}
return new MySQLRecord($res);
}
/**
* InsertID
* @return int
*/
function lastInsertId()
{
return mysql_insert_id($this->conn);
}
function quote($value)
{
return mysql_real_escape_string($value, $this->conn);
}
/**
* ,
*/
protected function checkConnection()
{
if (!@$this->ping())
{
$this->close();
return $this->connect();
}
return true;
}
function ping()
{
if (!mysql_ping($this->conn))
{
return false;
}
else
{
return true;
}
}
/**
*
*
* @return int
*/
function affected_rows()
{
return mysql_affected_rows($this->conn);
}
/**
*
*
* @see libs/system/IDatabase#close()
*/
function close()
{
mysql_close($this->conn);
}
/**
*
* @return int
*/
function getAffectedRows()
{
return mysql_affected_rows($this->conn);
}
/**
*
* @return int
*/
function errno()
{
return mysql_errno($this->conn);
}
}
class MySQLRecord implements \Swoole\IDbRecord
{
public $result;
function __construct($result)
{
$this->result = $result;
}
function fetch()
{
return mysql_fetch_assoc($this->result);
}
function fetchall()
{
$data = array();
while ($record = mysql_fetch_assoc($this->result))
{
$data[] = $record;
}
return $data;
}
function free()
{
mysql_free_result($this->result);
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Swoole\Database;
use Swoole;
/**
* MySQL
*
* @package SwooleExtend
* @author Tianfeng.Han
*
*/
class MySQL implements \Swoole\IDatabase
{
public $debug = false;
public $conn = null;
public $config;
const DEFAULT_PORT = 3306;
function __construct($db_config)
{
if (empty($db_config['port']))
{
$db_config['port'] = self::DEFAULT_PORT;
}
$this->config = $db_config;
}
/**
*
*
* @see Swoole.IDatabase::connect()
*/
function connect()
{
$db_config = $this->config;
if (empty($db_config['persistent']))
{
$this->conn = mysql_connect($db_config['host'] . ':' . $db_config['port'],
$db_config['user'],
$db_config['passwd']);
}
else
{
$this->conn = mysql_pconnect($db_config['host'] . ':' . $db_config['port'],
$db_config['user'],
$db_config['passwd']);
}
if (!$this->conn)
{
Swoole\Error::info(__CLASS__." SQL Error", mysql_error($this->conn));
return false;
}
mysql_select_db($db_config['name'], $this->conn) or Swoole\Error::info("SQL Error", mysql_error($this->conn));
if ($db_config['setname'])
{
mysql_query('set names ' . $db_config['charset'], $this->conn) or Swoole\Error::info("SQL Error",
mysql_error($this->conn));
}
return true;
}
function errorMessage($sql)
{
return mysql_error($this->conn) . "<hr />$sql<hr />MySQL Server: {$this->config['host']}:{$this->config['port']}";
}
/**
* SQL
*
* @param string $sql SQL
*
* @return MySQLRecord | false
*/
function query($sql)
{
$res = false;
for ($i = 0; $i < 2; $i++)
{
$res = mysql_query($sql, $this->conn);
if ($res === false)
{
if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013)
{
$r = $this->checkConnection();
if ($r === true)
{
continue;
}
}
\Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
return false;
}
break;
}
if (!$res)
{
Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
return false;
}
if (is_bool($res))
{
return $res;
}
return new MySQLRecord($res);
}
/**
* InsertID
* @return int
*/
function lastInsertId()
{
return mysql_insert_id($this->conn);
}
function quote($value)
{
return mysql_real_escape_string($value, $this->conn);
}
/**
* ,
*/
protected function checkConnection()
{
if (!@$this->ping())
{
$this->close();
return $this->connect();
}
return true;
}
function ping()
{
if (!mysql_ping($this->conn))
{
return false;
}
else
{
return true;
}
}
/**
*
*
* @return int
*/
function affected_rows()
{
return mysql_affected_rows($this->conn);
}
/**
*
*
* @see libs/system/IDatabase#close()
*/
function close()
{
mysql_close($this->conn);
}
/**
*
* @return int
*/
function getAffectedRows()
{
return mysql_affected_rows($this->conn);
}
/**
*
* @return int
*/
function errno()
{
return mysql_errno($this->conn);
}
}
class MySQLRecord implements \Swoole\IDbRecord
{
public $result;
function __construct($result)
{
$this->result = $result;
}
function fetch()
{
return mysql_fetch_assoc($this->result);
}
function fetchall()
{
$data = array();
while ($record = mysql_fetch_assoc($this->result))
{
$data[] = $record;
}
return $data;
}
function free()
{
mysql_free_result($this->result);
}
}
Function Calls
None |
Stats
MD5 | e556c3b8f1497700d29b5ea283b6e7b2 |
Eval Count | 0 |
Decode Time | 132 ms |