-
- class HRDB{
- protected $pdo;
- protected $res;
- protected $config;
-
- /*???* /
- function __construct($config){
- $this->Config = $config;
- $this->connect();
- }
-
- /*?????? ?? * /
- ?? ?? connect(){
- $this->pdo = new PDO($this->Config['dsn'], $this->Config['name'], $this - >Config['password']);
- $this->pdo->query('set names utf8;');
- //??? stdClass? ???
- //$this - >pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
- //??? ???? ??? ?? ?????
- $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO ::ERRMODE_EXCEPTION);
- }
-
- /*?????? ??*/
- ?? ?? close(){
- $this->pdo = null;
- }
-
- ?? ?? ??($sql){
- $res = $this->pdo->query($sql);
- if($res){
- $this->res = $res;
- }
- }
- ?? ?? exec($sql){
- $res = $this->pdo->exec($sql);
- if($ res ){
- $this->res = $res;
- }
- }
- ?? ?? fetchAll(){
- return $this->res->fetchAll();
- }
- ?? ?? fetch(){
- return $this->res->fetch();
- }
- public function fetchColumn(){
- return $this- > ;res->fetchColumn();
- }
- ?? ?? lastInsertId(){
- return $this->res->lastInsertId();
- }
-
- / **
- * ???? ??
- * int $debug ??? ??? ??, ????? sql ?? ?????.
- * 0 ????
- * 1 ???
- * 2 ??? ??? ? ?? ????
- * int $ ?? ?? ??
- * 0? ?? ???? ?????.
- * 1? ?? ???? ?????.
- * 2 ? ?? ?????.
- * ???/?? $table ?????? ???, two ? ?? ??
- * ?? ??:
- * 'tb_member, tb_money'
- * ?? ??:
- * array('tb_member', 'tb_money')
- * ???/?? $fields ??? ?????? ??, ??? ? ??, ???? ?? ??, ? ?? ? ?? ??
- * ?? ??:
- * '??? ??, ????'
- * ?? ??:
- * array('username', 'password')
- * ???/?? $sqlwhere ?? ??, ?? ?? ??, ? ?? ? ?? ??
- * ?? ??:
- * 'and type = 1 ? ??? ?? like " %os%"'
- * ?? ?? :
- * array('type = 1', 'username like "%os%"')
- * string $orderby ??, ???? id ??
- */
- ?? ?? ??($debug, $mode, $table, $fields="*", $sqlwhere="", $orderby="tbid desc"){
- / / ???? ??
- if(is_array($table)){
- $table = implode(', ', $table);
- }
- if(is_array($fields)){
- $ fields = implode(', ', $fields);
- }
- if(is_array($sqlwhere)){
- $sqlwhere = ' and '.implode(' and ', $sqlwhere);
- }
- //?????? ??
- if($debug === 0){
- if($mode === 2){
- $this->query("select count( tbid ) from $table where 1=1 $sqlwhere");
- $return = $this->fetchColumn();
- }else if($mode === 1){
- $this- > ;query("select $fields from $table where 1=1 $sqlwhere order by $orderby");
- $return = $this->fetch();
- }else{
- $this - >query("select $fields from $table where 1=1 $sqlwhere order by $orderby");
- $return = $this->fetchAll();
- }
- return $return ;
- }else{
- if($mode === 2){
- echo "$table?? ??(tbid) ??, ??? 1=1 $sqlwhere";
- }else if($mode = == 1){
- echo "$table?? $fields ??, ??? 1=1 $sqlwhere order by $orderby";
- }
- else{
- echo "1=1? $sql?? $orderby? ??? $table?? $fields ??";
- }
- if($debug === 2){
- exit;
- }
- }
- }
-
- /**
- * ???? ??
- * int $debug ??? ??? ??, ????? sql ?? ?????.
- * 0 ????
- * 1 ???
- * 2 ??? ??? ? ?? ????
- * int $ ?? ?? ??
- * 0 ?? ?? ??
- * 1 ?? ?? ?? ??
- * 2 ????? ??? ???? ID? ??
- * ???/?? $ ??? ?????? ???, ? ?? ? ?? ??
- * ?? ??:
- * 'tb_member, tb_money'
- * ?? ??:
- * array('tb_member', 'tb_money')
- * string/array $set ??? ???? Content, ? ?? ? ?? ??
- * ?? ??:
- * 'username = "test", type = 1, dt = now()'
- * Array ??:
- * array('username = "test"', 'type = 1', 'dt = now()')
- */
- ?? ?? ??($debug, $mode, $table, $set){
- / /參數(shù)處理
- if(is_array($table)){
- $table = implode(', ', $table);
- }
- if(is_array($set)){
- $set = implode(', ', $set);
- }
- //數(shù)據(jù)庫操?
- if($debug === 0){
- if($mode === 2){
- $this->query("$table set $set? ??");
- $return = $this->lastInsertId();
- }else if($mode === 1) {
- $this->exec("$table set $set? ??");
- $return = $this->res;
- }else{
- $this->query ("$table set $set? ??");
- $return = NULL;
- }
- return $return;
- }else{
- echo "$table set $set? ??" ;
- if($debug === 2){
- ??;
- }
- }
- }
-
- /**
- * ???? ??
- * int $debug ??? ??? ??, ????? sql ?? ?????.
- * 0 ????
- * 1 ???
- * 2 ??? ??? ? ?? program
- * int $ ?? ?? ??
- * 0 ?? ?? ??
- * 1 ?? ?? ? ??
- * ??? $table ?????? ???, ? ?? ? ?? ??
- * ?? ??:
- * 'tb_member, tb_money'
- * ?? ??:
- * array('tb_member', 'tb_money')
- * string/array $set ????? ??? ?? ? ??, ? 2? -?? ??
- * ?? ??:
- * 'username = "test", type = 1, dt = now()'
- * ?? ??:
- * array('username = "test" ', 'type = 1', 'dt = now()')
- * ???/?? $sqlwhere ?? ??, ?? ??, ? ?? ? ?? ?? ??
- * ?? ??:
- * 'and type = 1 ? ??? ?? like "%os% "'
- * ?? ??:
- * array('type = 1', 'username like "%os%"')
- */
- ?? ?? update($debug, $mode, $table, $set, $sqlwhere=""){
- //參數(shù)處理
- if(is_array($table)){
- $table = implode(', ', $table);
- }
- if(is_array($set)){
- $set = implode(', ', $set);
- }
- if(is_array($ sqlwhere)){
- $sqlwhere = ' and '.implode(' and ', $sqlwhere);
- }
- //數(shù)據(jù)庫操?
- if($debug === 0){
- if($mode === 1){
- $this->exec("update $table set $set where 1=1 $sqlwhere");
- $return = $this->res;
- }else{
- $this->query("update $table set $set where 1=1 $sqlwhere");
- $return = NULL;
- }
- return $return ;
- }else{
- echo "$table set $set ????, ??? 1=1 $sqlwhere";
- if($debug === 2){
- exit;
- }
- }
- }
-
- /**
- * ???? ??
- * int $debug ??? ??? ??, ????? sql ?? ?????.
- * 0 ????
- * 1 ???
- * 2 ??? ??? ? ?? program
- * int $ mode return type
- * 0 ?? ?? ??
- * 1 ?? ?? ?? ??
- * string $table ?????? ???
- * string/array $sqlwhere ?? ??, ?? ?? ???? ? ?? ? ?? ??
- * ?? ??:
- * 'and type = 1 ? ??? ??? "%os%"''
- * ?? ??:
- * array('type = 1', '??? ??? "%os %"? ????')
- */
- ?? ?? delete($debug, $mode, $table, $sqlwhere=""){
- //參數(shù)處理
- if( is_array($sqlwhere)){
- $sqlwhere = ' and '.implode(' and ', $sqlwhere);
- }
- //數(shù)據(jù)庫操?
- if($debug === 0) {
- if($mode === 1){
- $this->exec("1=1 $sqlwhere? $table?? ??");
- $return = $this->res ;
- }else{
- $this->query("1=1 $sqlwhere? $table?? ??");
- $return = NULL;
- }
- return $return;
- }else{
- echo "1=1? $sqlwhere?? ??";
- if($debug === 2){
- exit;
- }
- }
- }
- }
復代碼
|