<?php // 파일명 : dbDataClass.php
class DBDataClass { //DB-UID데이터 function getUidData($table,$uid) { return $this->getDbData($table,'uid='.(int)$uid,'*'); // 'uid='.(int)$uid }
// DB Query Cutom 함수 function getDbData($table,$where,$column) { global $db; $sql ='select '.$column.' from '.$table.($where?' where '.$this->getSqlFilter($where):''); //echo $sql; // 디버깅 목적으로 필요할 때가 있다. $result = mysqli_query($db,$sql); $row = mysqli_fetch_array($result); return $row; }
// DB Query result 함수 function getDbresult($table,$where,$column) { global $db; $sql = 'select '.$column.' from '.$table.($where?' where '.$this->getSqlFilter($where):''); $result = mysqli_query($db,$sql); return $result; }
//DB데이터 ARRAY -> 테이블에 출력할 데이터 배열 function getDbArray($table,$where,$flddata,$orderby,$rowsPage,$curPage){ global $db; $sql ='select '.$flddata.' from '.$table.($where?' where '.$this->getSqlFilter($where):'').($orderby?' order by '.$orderby:'').($rowsPage?' limit '.(($curPage-1)*$rowsPage).', '.$rowsPage:''); //echo $sql; $result = mysqli_query($db,$sql); return $result;
}
//DB데이터 레코드 총 개수 function getDbRows($table,$where){ global $db; $sql = 'select count(*) from '.$table.($where?' where '.$this->getSqlFilter($where):''); $result = mysqli_query($db,$sql); if($result){ $rows = mysqli_fetch_row($result); return $rows[0] ? $rows[0] : 0; } else { echo "Failed to connect to MySQL: " . mysqli_connect_error($db); exit(); // **this is missing** } }
//DB삽입 function getDbInsert($table,$key,$val){ global $db; $sql ="insert into ".$table." (".$key.")values(".$val.")"; //echo $sql; if(mysqli_query($db,$sql)){ return 1; } else { return 0; } }
//DB업데이트 function getDbUpdate($table,$set,$where){ global $db; mysqli_query($db,'set names utf8'); mysqli_query($db,'set sql_mode=\'\''); $sql ="update ".$table." set ".$set.($where?' where '.$this->getSqlFilter($where):''); if(mysqli_query($db,$sql)){ return 1; } else { return 0; } }
//DB삭제 function getDbDelete($table,$where) { global $db; $sql ="delete from ".$table.($where?' where '.$this->getSqlFilter($where):''); if(mysqli_query($db,$sql)){ return 1; } else { return 0; } }
//SQL필터링 function getSqlFilter($sql) { return $sql; }
// 암호화 function AES_Encode($plain_text){ global $key; return base64_encode(openssl_encrypt($plain_text, "aes-256-cbc", $key, true, str_repeat(chr(0), 16))); }
// 복호화 function AES_Decode($base64_text){ global $key; return openssl_decrypt(base64_decode($base64_text), "aes-256-cbc", $key, true, str_repeat(chr(0), 16)); }
}//end dbClass
?>
|