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 header("Content-Type:text/html;charset=utf-8"); class PdoMysql{ public static $..

Decoded Output download

<?php 
header("Content-Type:text/html;charset=utf-8"); 
class PdoMysql{ 
  public static $config = array();// 
  public static $link = null;// 
  public static $pconnect = false;// 
  public static $dbVersion = null;// 
  public static $connected = false;// 
  public static $PDOStatement = null;//PDOStatement 
  public static $queryStr = null;// 
  public static $error = null;// 
  public static $lastInsertId = null;//AUTO_INCREMANT 
  public static $numRows = null;// 
  /** 
   *  
   * 
   * @param   array|string $dbConfig The database configuration 
   * 
   * @return   boolean    ( description_of_the_return_value ) 
   */ 
  public function __construct($dbConfig=''){ 
	global $db_host, $db_username, $db_password, $db_database, $db_port, $db_char; 
    if(!class_exists("PDO")){ 
      self::throw_exception("PDO,"); 
    } 
    if(!is_array($dbConfig)){ 
      $dbConfig = array( 
              'hostname' => $db_host, 
              'username' => $db_username, 
              'password' => $db_password, 
              'database' => $db_database, 
              'hostport' => $db_port, 
              'dbms'   => 'mysql', 
              'dsn'   => "mysql:host=".$db_host.";dbname=".$db_database 
            ); 
    } 
    if(empty($dbConfig['hostname'])){ 
      self::throw_exception(","); 
    } 
    self::$config = $dbConfig; 
    if(empty(self::$config['params'])){ 
      self::$config['params'] = array(); 
    } 
    if(!isset(self::$link)){ 
      $configs = self::$config; 
      if(self::$pconnect){ 
        //, 
        $configs['params'][constant("PDO::ATTR_PERSISTENT")] = true; 
      } 
      try { 
        self::$link = new PDO($configs['dsn'],$configs['username'],$configs['password'],$configs['params']); 
      } catch (PDOException $e) { 
        self::throw_exception($e->getMessage()); 
      } 
      if(!self::$link){ 
        self::throw_exception("PDO"); 
        return false; 
      } 
      self::$link->exec("set names utf8"); 
      self::$dbVersion = self::$link->getAttribute(constant("PDO::ATTR_SERVER_VERSION")); 
      unset($configs); 
    } 
  } 
  /** 
   *  
   * 
   * @param   <type> $sql  The sql 
   * 
   * @return   <type> All. 
   */ 
  public static function getAll($sql=null){ 
    if($sql!=null){ 
      self::query($sql); 
    } 
    $result = self::$PDOStatement->fetchAll(constant("PDO::FETCH_ASSOC")); 
    return $result; 
  } 
  /** 
   *  
   * 
   * @param   <type> $sql  The sql 
   * 
   * @return   <type> The row. 
   */ 
  public static function getRow($sql=null){ 
    if($sql!=null){ 
      self::query($sql); 
    } 
    $result = self::$PDOStatement->fetch(constant("PDO::FETCH_ASSOC")); 
    return $result; 
  } 
 
    /* 
        @ 
        @param $table  
        @param $where  
        @return  number 
    */ 
  public static function getAllnum($table, $where = null){ 
	    $sql = ''; 
        if (is_null($where)) { 
            $sql .= 'select count(*) from '.$table; 
        } else { 
            $sql .= 'select count(*) from '.$table.' WHERE '.$where; 
        } 
	    self::query($sql); 
        $row_count = self::$PDOStatement->fetch(); 
        return $row_count[0];   
  } 
	 
  /** 
   *  
   * 
   * @param   <type>  $sql  The sql 
   * 
   * @return   boolean ( description_of_the_return_value ) 
   */ 
  public static function execute($sql=null){ 
    $link = self::$link; 
    if(!$link)return false; 
    if($sql!=null){ 
      self::$queryStr = $sql; 
    } 
    if(!empty(self::$PDOStatement))self::free(); 
    $result = $link->exec(self::$queryStr); 
    self::haveErrorThrowException(); 
    if($result){ 
      self::$lastInsertId = $link->lastInsertId(); 
      self::$numRows = $result; 
      return $result; 
    }else{ 
      return false; 
    } 
  } 
  /** 
   *  
   * 
   * @param   <type> $tabName The tab name 
   * @param   <type> $priId  The pri identifier 
   * @param   string $fields  The fields 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function findById($tabName,$priId,$fields='*'){ 
    $sql = 'SELECT %s FROM %s WHERE id=%d'; 
    return self::getRow(sprintf($sql,self::parseFields($fields),$tabName,$priId)); 
  } 
  /** 
   *  
   * 
   * @param   <type> $tables The tables 
   * @param   <type> $where  The where 
   * @param   string $fields The fields 
   * @param   <type> $group  The group 
   * @param   <type> $having The having 
   * @param   <type> $order  The order 
   * @param   <type> $limit  The limit 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function find($tables,$where=null,$fields='*',$group=null,$having=null,$order=null,$limit 
    =null){ 
    $sql = 'SELECT '.self::parseFields($fields).' FROM '.$tables 
    .self::parseWhere($where) 
    .self::parseGroup($group) 
    .self::parseHaving($having) 
    .self::parseOrder($order) 
    .self::parseLimit($limit); 
    $data = self::getAll($sql); 
    return $data; 
  } 
  /** 
   *  
   * 
   * @param   <type> $data  The data 
   * @param   <type> $table The table 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function add($data,$table){ 
    $keys = array_keys($data); 
    array_walk($keys, array('PdoMySQL','addSpecialChar')); 
    $fieldsStr = join(',',$keys); 
    $values = "'".join("','",array_values($data))."'"; 
    $sql = "INSERT {$table}({$fieldsStr}) VALUES({$values})"; 
    return self::execute($sql); 
  } 
  /** 
   *  
   * 
   * @param   <type> $data  The data 
   * @param   <type> $table The table 
   * @param   <type> $where The where 
   * @param   <type> $order The order 
   * @param   <type> $limit The limit 
   */ 
  public static function update($data,$table,$where=null,$order=null,$limit=null){ 
    $sets = ''; 
    foreach ($data as $key => $value) { 
      $sets .= $key."='".$value."',"; 
    } 
    $sets = rtrim($sets,','); 
    $sql = "UPDATE {$table} SET {$sets}".self::parseWhere($where).self::parseOrder($order).self::parseLimit($limit); 
    return self::execute($sql); 
  } 
  /** 
   *  
   * 
   * @param   <type> $data  The data 
   * @param   <type> $table The table 
   * @param   <type> $where The where 
   * @param   <type> $order The order 
   * @param   <type> $limit The limit 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function delete($table,$where=null,$order=null,$limit=null){ 
    $sql = "DELETE FROM {$table} ".self::parseWhere($where).self::parseOrder($order).self::parseLimit($limit); 
    return self::execute($sql); 
  } 
  /** 
   *  
   * 
   * @param   string  $sql  The sql 
   * 
   * @return   boolean ( description_of_the_return_value ) 
   */ 
  public static function query($sql=''){ 
    $link = self::$link; 
    if(!$link)return false; 
    // 
    if(!empty(self::$PDOStatement))self::free(); 
    self::$queryStr = $sql; 
    self::$PDOStatement = $link->prepare(self::$queryStr); 
    $res = self::$PDOStatement->execute(); 
    self::haveErrorThrowException(); 
    return $res; 
  } 
  /** 
   * sql 
   * 
   * @return   boolean The last sql. 
   */ 
  public static function getLastSql(){ 
    $link = self::$link; 
    if(!$link){ 
      return false; 
    } 
    return self::$queryStr; 
  } 
  /** 
   * ID 
   * 
   * @return   boolean The last insert identifier. 
   */ 
  public static function getLastInsertId(){ 
    $link = self::$link; 
    if(!$link){ 
      return false; 
    } 
    return self::$lastInsertId; 
  } 
  /** 
   *  
   * 
   * @return   boolean The database version. 
   */ 
  public static function getDbVersion(){ 
    $link = self::$link; 
    if(!$link){ 
      return false; 
    } 
    return self::$dbVersion; 
  } 
  /** 
   *  
   * 
   * @return   array ( description_of_the_return_value ) 
   */ 
  public static function showTables(){ 
    $tables = array(); 
    if(self::query("show tables")){ 
      $result = self::getAll(); 
      foreach ($result as $key => $value) { 
        $tables[$key] = current($value); 
      } 
    } 
    return $tables; 
  } 
  /** 
   * where 
   * 
   * @param   <type> $where The where 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function parseWhere($where){ 
    $whereStr = ''; 
    if(is_string($where)&&!empty($where)){ 
      $whereStr = $where; 
    } 
    return empty($whereStr) ? '' : ' WHERE '.$whereStr; 
  } 
  /** 
   * group 
   * 
   * @param   <type> $group The group 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function parseGroup($group){ 
    $groupStr = ''; 
    if(is_array($group)){ 
      $groupStr = implode(',', $group); 
    }elseif(is_string($group)&&!empty($group)){ 
      $groupStr = $group; 
    } 
    return empty($groupStr) ? '' : ' GROUP BY '.$groupStr; 
  } 
  /** 
   * having 
   * 
   * @param   <type> $having The having 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function parseHaving($having){ 
    $havingStr = ''; 
    if(is_string($having)&&!empty($having)){ 
      $havingStr = $having; 
    } 
    return empty($havingStr) ? '' : ' HAVING '.$havingStr; 
  } 
  /** 
   * order 
   * 
   * @param   <type> $order The order 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function parseOrder($order){ 
    $orderStr = ''; 
    if(is_string($order)&&!empty($order)){ 
      $orderStr = $order; 
    } 
    return empty($orderStr) ? '' : ' ORDER BY '.$orderStr; 
  } 
  /** 
   * limit 
   * 
   * @param   <type> $limit The limit 
   * 
   * @return   <type> ( description_of_the_return_value ) 
   */ 
  public static function parseLimit($limit){ 
    $limitStr = ''; 
    if(is_array($limit)){ 
      $limitStr = implode(',', $limit); 
    }elseif(is_string($limit)&&!empty($limit)){ 
      $limitStr = $limit; 
    } 
    return empty($limitStr) ? '' : ' LIMIT '.$limitStr; 
  } 
  /** 
   *  
   * 
   * @param   <type> $fields The fields 
   * 
   * @return   string ( description_of_the_return_value ) 
   */ 
public static function parseFields($fields){ 
    if(is_array($fields)){ 
        array_walk($fields, array('PdoMySQL','addSpecialChar')); 
        $fieldsStr = implode(',', $fields); 
    } elseif (is_string($fields) && !empty($fields)) { 
        $fieldsArray = explode(',', $fields); 
        $parsedFields = array_map(function($field) { 
            //  
            return preg_match('/\(.+\)/', $field) ? $field : '`' . trim($field) . '`'; 
        }, $fieldsArray); 
        $fieldsStr = implode(',', $parsedFields); 
    } else { 
        $fieldsStr = "*"; 
    } 
    return $fieldsStr;  
} 
 
  /** 
   *  
   * 
   * @param   string $value The value 
   * 
   * @return   string ( description_of_the_return_value ) 
   */ 
  public static function addSpecialChar(&$value){ 
    if($value==="*"||strpos($value,'.')!==false||strpos($value,'`')!==false){ 
      // 
    }elseif(strpos($value, '`')===false){ 
      $value = '`'.trim($value).'`'; 
    } 
    return $value; 
  } 
  /** 
   *  
   */ 
  public static function free(){ 
    self::$PDOStatement = null; 
  } 
  /** 
   *  
   * 
   * @return   boolean ( description_of_the_return_value ) 
   */ 
  public static function haveErrorThrowException(){ 
    $obj = empty(self::$PDOStatement) ? self::$link : self::$PDOStatement; 
    $arrError = $obj->errorInfo(); 
    if($arrError[0]!='00000'){ 
      self::$error = 'SQLSTATE=>'.$arrError[0].'<br/>SQL Error=>'.$arrError[2].'<br/>Error SQL=>'.self::$queryStr; 
      self::throw_exception(self::$error); 
      return false; 
    } 
    if(self::$queryStr==''){ 
      self::throw_exception('SQL'); 
      return false; 
    } 
  } 
  /** 
   *  
   * 
   * @param   <type> $errMsg The error message 
   */ 
  public static function throw_exception($errMsg){ 
    echo $errMsg; 
  } 
  /** 
   *  
   */ 
  public static function close(){ 
    self::$link = null; 
  } 
} 
 ?>

Did this file decode correctly?

Original Code

<?php
header("Content-Type:text/html;charset=utf-8");
class PdoMysql{
  public static $config = array();//
  public static $link = null;//
  public static $pconnect = false;//
  public static $dbVersion = null;//
  public static $connected = false;//
  public static $PDOStatement = null;//PDOStatement
  public static $queryStr = null;//
  public static $error = null;//
  public static $lastInsertId = null;//AUTO_INCREMANT
  public static $numRows = null;//
  /**
   * 
   *
   * @param   array|string $dbConfig The database configuration
   *
   * @return   boolean    ( description_of_the_return_value )
   */
  public function __construct($dbConfig=''){
	global $db_host, $db_username, $db_password, $db_database, $db_port, $db_char;
    if(!class_exists("PDO")){
      self::throw_exception("PDO,");
    }
    if(!is_array($dbConfig)){
      $dbConfig = array(
              'hostname' => $db_host,
              'username' => $db_username,
              'password' => $db_password,
              'database' => $db_database,
              'hostport' => $db_port,
              'dbms'   => 'mysql',
              'dsn'   => "mysql:host=".$db_host.";dbname=".$db_database
            );
    }
    if(empty($dbConfig['hostname'])){
      self::throw_exception(",");
    }
    self::$config = $dbConfig;
    if(empty(self::$config['params'])){
      self::$config['params'] = array();
    }
    if(!isset(self::$link)){
      $configs = self::$config;
      if(self::$pconnect){
        //,
        $configs['params'][constant("PDO::ATTR_PERSISTENT")] = true;
      }
      try {
        self::$link = new PDO($configs['dsn'],$configs['username'],$configs['password'],$configs['params']);
      } catch (PDOException $e) {
        self::throw_exception($e->getMessage());
      }
      if(!self::$link){
        self::throw_exception("PDO");
        return false;
      }
      self::$link->exec("set names utf8");
      self::$dbVersion = self::$link->getAttribute(constant("PDO::ATTR_SERVER_VERSION"));
      unset($configs);
    }
  }
  /**
   * 
   *
   * @param   <type> $sql  The sql
   *
   * @return   <type> All.
   */
  public static function getAll($sql=null){
    if($sql!=null){
      self::query($sql);
    }
    $result = self::$PDOStatement->fetchAll(constant("PDO::FETCH_ASSOC"));
    return $result;
  }
  /**
   * 
   *
   * @param   <type> $sql  The sql
   *
   * @return   <type> The row.
   */
  public static function getRow($sql=null){
    if($sql!=null){
      self::query($sql);
    }
    $result = self::$PDOStatement->fetch(constant("PDO::FETCH_ASSOC"));
    return $result;
  }

    /*
        @
        @param $table 
        @param $where 
        @return  number
    */
  public static function getAllnum($table, $where = null){
	    $sql = '';
        if (is_null($where)) {
            $sql .= 'select count(*) from '.$table;
        } else {
            $sql .= 'select count(*) from '.$table.' WHERE '.$where;
        }
	    self::query($sql);
        $row_count = self::$PDOStatement->fetch();
        return $row_count[0];  
  }
	
  /**
   * 
   *
   * @param   <type>  $sql  The sql
   *
   * @return   boolean ( description_of_the_return_value )
   */
  public static function execute($sql=null){
    $link = self::$link;
    if(!$link)return false;
    if($sql!=null){
      self::$queryStr = $sql;
    }
    if(!empty(self::$PDOStatement))self::free();
    $result = $link->exec(self::$queryStr);
    self::haveErrorThrowException();
    if($result){
      self::$lastInsertId = $link->lastInsertId();
      self::$numRows = $result;
      return $result;
    }else{
      return false;
    }
  }
  /**
   * 
   *
   * @param   <type> $tabName The tab name
   * @param   <type> $priId  The pri identifier
   * @param   string $fields  The fields
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function findById($tabName,$priId,$fields='*'){
    $sql = 'SELECT %s FROM %s WHERE id=%d';
    return self::getRow(sprintf($sql,self::parseFields($fields),$tabName,$priId));
  }
  /**
   * 
   *
   * @param   <type> $tables The tables
   * @param   <type> $where  The where
   * @param   string $fields The fields
   * @param   <type> $group  The group
   * @param   <type> $having The having
   * @param   <type> $order  The order
   * @param   <type> $limit  The limit
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function find($tables,$where=null,$fields='*',$group=null,$having=null,$order=null,$limit
    =null){
    $sql = 'SELECT '.self::parseFields($fields).' FROM '.$tables
    .self::parseWhere($where)
    .self::parseGroup($group)
    .self::parseHaving($having)
    .self::parseOrder($order)
    .self::parseLimit($limit);
    $data = self::getAll($sql);
    return $data;
  }
  /**
   * 
   *
   * @param   <type> $data  The data
   * @param   <type> $table The table
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function add($data,$table){
    $keys = array_keys($data);
    array_walk($keys, array('PdoMySQL','addSpecialChar'));
    $fieldsStr = join(',',$keys);
    $values = "'".join("','",array_values($data))."'";
    $sql = "INSERT {$table}({$fieldsStr}) VALUES({$values})";
    return self::execute($sql);
  }
  /**
   * 
   *
   * @param   <type> $data  The data
   * @param   <type> $table The table
   * @param   <type> $where The where
   * @param   <type> $order The order
   * @param   <type> $limit The limit
   */
  public static function update($data,$table,$where=null,$order=null,$limit=null){
    $sets = '';
    foreach ($data as $key => $value) {
      $sets .= $key."='".$value."',";
    }
    $sets = rtrim($sets,',');
    $sql = "UPDATE {$table} SET {$sets}".self::parseWhere($where).self::parseOrder($order).self::parseLimit($limit);
    return self::execute($sql);
  }
  /**
   * 
   *
   * @param   <type> $data  The data
   * @param   <type> $table The table
   * @param   <type> $where The where
   * @param   <type> $order The order
   * @param   <type> $limit The limit
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function delete($table,$where=null,$order=null,$limit=null){
    $sql = "DELETE FROM {$table} ".self::parseWhere($where).self::parseOrder($order).self::parseLimit($limit);
    return self::execute($sql);
  }
  /**
   * 
   *
   * @param   string  $sql  The sql
   *
   * @return   boolean ( description_of_the_return_value )
   */
  public static function query($sql=''){
    $link = self::$link;
    if(!$link)return false;
    //
    if(!empty(self::$PDOStatement))self::free();
    self::$queryStr = $sql;
    self::$PDOStatement = $link->prepare(self::$queryStr);
    $res = self::$PDOStatement->execute();
    self::haveErrorThrowException();
    return $res;
  }
  /**
   * sql
   *
   * @return   boolean The last sql.
   */
  public static function getLastSql(){
    $link = self::$link;
    if(!$link){
      return false;
    }
    return self::$queryStr;
  }
  /**
   * ID
   *
   * @return   boolean The last insert identifier.
   */
  public static function getLastInsertId(){
    $link = self::$link;
    if(!$link){
      return false;
    }
    return self::$lastInsertId;
  }
  /**
   * 
   *
   * @return   boolean The database version.
   */
  public static function getDbVersion(){
    $link = self::$link;
    if(!$link){
      return false;
    }
    return self::$dbVersion;
  }
  /**
   * 
   *
   * @return   array ( description_of_the_return_value )
   */
  public static function showTables(){
    $tables = array();
    if(self::query("show tables")){
      $result = self::getAll();
      foreach ($result as $key => $value) {
        $tables[$key] = current($value);
      }
    }
    return $tables;
  }
  /**
   * where
   *
   * @param   <type> $where The where
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function parseWhere($where){
    $whereStr = '';
    if(is_string($where)&&!empty($where)){
      $whereStr = $where;
    }
    return empty($whereStr) ? '' : ' WHERE '.$whereStr;
  }
  /**
   * group
   *
   * @param   <type> $group The group
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function parseGroup($group){
    $groupStr = '';
    if(is_array($group)){
      $groupStr = implode(',', $group);
    }elseif(is_string($group)&&!empty($group)){
      $groupStr = $group;
    }
    return empty($groupStr) ? '' : ' GROUP BY '.$groupStr;
  }
  /**
   * having
   *
   * @param   <type> $having The having
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function parseHaving($having){
    $havingStr = '';
    if(is_string($having)&&!empty($having)){
      $havingStr = $having;
    }
    return empty($havingStr) ? '' : ' HAVING '.$havingStr;
  }
  /**
   * order
   *
   * @param   <type> $order The order
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function parseOrder($order){
    $orderStr = '';
    if(is_string($order)&&!empty($order)){
      $orderStr = $order;
    }
    return empty($orderStr) ? '' : ' ORDER BY '.$orderStr;
  }
  /**
   * limit
   *
   * @param   <type> $limit The limit
   *
   * @return   <type> ( description_of_the_return_value )
   */
  public static function parseLimit($limit){
    $limitStr = '';
    if(is_array($limit)){
      $limitStr = implode(',', $limit);
    }elseif(is_string($limit)&&!empty($limit)){
      $limitStr = $limit;
    }
    return empty($limitStr) ? '' : ' LIMIT '.$limitStr;
  }
  /**
   * 
   *
   * @param   <type> $fields The fields
   *
   * @return   string ( description_of_the_return_value )
   */
public static function parseFields($fields){
    if(is_array($fields)){
        array_walk($fields, array('PdoMySQL','addSpecialChar'));
        $fieldsStr = implode(',', $fields);
    } elseif (is_string($fields) && !empty($fields)) {
        $fieldsArray = explode(',', $fields);
        $parsedFields = array_map(function($field) {
            // 
            return preg_match('/\(.+\)/', $field) ? $field : '`' . trim($field) . '`';
        }, $fieldsArray);
        $fieldsStr = implode(',', $parsedFields);
    } else {
        $fieldsStr = "*";
    }
    return $fieldsStr; 
}

  /**
   * 
   *
   * @param   string $value The value
   *
   * @return   string ( description_of_the_return_value )
   */
  public static function addSpecialChar(&$value){
    if($value==="*"||strpos($value,'.')!==false||strpos($value,'`')!==false){
      //
    }elseif(strpos($value, '`')===false){
      $value = '`'.trim($value).'`';
    }
    return $value;
  }
  /**
   * 
   */
  public static function free(){
    self::$PDOStatement = null;
  }
  /**
   * 
   *
   * @return   boolean ( description_of_the_return_value )
   */
  public static function haveErrorThrowException(){
    $obj = empty(self::$PDOStatement) ? self::$link : self::$PDOStatement;
    $arrError = $obj->errorInfo();
    if($arrError[0]!='00000'){
      self::$error = 'SQLSTATE=>'.$arrError[0].'<br/>SQL Error=>'.$arrError[2].'<br/>Error SQL=>'.self::$queryStr;
      self::throw_exception(self::$error);
      return false;
    }
    if(self::$queryStr==''){
      self::throw_exception('SQL');
      return false;
    }
  }
  /**
   * 
   *
   * @param   <type> $errMsg The error message
   */
  public static function throw_exception($errMsg){
    echo $errMsg;
  }
  /**
   * 
   */
  public static function close(){
    self::$link = null;
  }
}

Function Calls

header 1

Variables

None

Stats

MD5 98987ae78a03302b6d2b7ac96c9d1de6
Eval Count 0
Decode Time 94 ms