<?
class ClassDB_Hawk5_Mysql {
// PRIVATE 변수
VAR $CONN; // DB 커넥션 변수
VAR $ERR_QUERY; // 에러가 발생한 쿼리
VAR $ERR_MSG; // 에러 메세지
VAR $RESULT; // 쿼리 결과
VAR $REC_COUNT; // 레코드 합계
VAR $ROW; // 레코드 결과 FETCH
VAR $ROWNUM; // 현재 레코드 번호
//클래스 생성자..
//클래스를 생성하면.. 자동으로 실행된다..
function ClassDB_Hawk5_Mysql() {
$DB_HOST = "localhost";
$DB_USER = "hawk5";
$DB_PWD = "hawk5";
$DB_NAME = "DB_hawk5";
$this->CONN = mysql_connect($DB_HOST, $DB_USER, $DB_PWD) or die("디비연결 실패지롱!");
mysql_select_db($DB_NAME, $this->CONN) or die("디비명 똑바로 입력해랑");
}
// 쿼리문 실행
function Execute($query) {
$this->ERR_MSG = "";
if (!$this->RESULT = mysql_query($query)) {
$this->ERR_QUERY = $query;
$this->ERR_MSG = mysql_error();
return false;
}else{
$this->REC_COUNT = mysql_num_rows($this->RESULT);
$this->ROW = mysql_fetch_bject($this->RESULT);
$this->ROWNUM = 0;
}
}
// RecordCount
function RecordCount() {
return $this->REC_COUNT;
}
// 레코드 처음
function MoveFirst() {
mysql_data_seek($this->RESULT, 0);
$this->ROW = mysql_fetcht_assoct($this->RESULT);
}
// 레코드 마지막
function MoveLast() {
mysql_data_seek($this->RESULT, $this->REC_COUNT - 1);
$this->ROW = mysql_fetcht_assoct($this->RESULT);
}
// 다음 레코드
function MoveNext() {
$this->ROWNUM = $this->ROWNUM + 1;
if ($this->ROWNUM < $this->REC_COUNT) {
mysql_data_seek($this->RESULT, $this->ROWNUM);
$this->ROW = mysql_fetcht_assoct($this->RESULT);
return true;
}
else { return false; }
}
// 이전 레코드
function MovePrev() {
$this->ROWNUM = $this->ROWNUM - 1;
if ($this->ROWNUM >= 0) {
mysql_data_seek($this->RESULT, $this->ROWNUM);
$this->ROW = mysql_fetcht_assoct($this->RESULT);
return true;
}
else { return false; }
}
// 필드값 가져오기
function Field($field_name) {
return $this->ROW[$field_name];
}
// 데이터베이스 접속 종료
function Close() {
mysql_close($this->CONN);
}
//에러메서지를 보여준다
function ShowError() {
if (strlen($this->ERR_MSG) > 0) {
$msg = "<h2 align=\"center\">SQL ERROR!</h2>";
$msg .= "<table border=0>";
$msg .= "<tr><td bgcolor=\"green\">";
$msg .= "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\"width=\"600\" height=\"88\">";
$msg .= "<tr><th height=\"16\"><font color=\"#FFFFFF\">실행된 SQL</font></th></tr>";
$msg .= "<tr><td bgcolor=\"white\" height=\"16\" align=\"center\">".$this->QUERY."</td></tr>";
$msg .= "<tr<th height=\"16\"><font color=\"#FFFFFF\">Error 내용</font></th></tr>";
$msg .= "<tr><td bgcolor=\"white\" height=\"28\" align=\"center\">".$this->ERR_MSG."</td></tr>";
$msg .= "</table>";
$msg .= "</td>";
$msg .= "</tr>";
$msg .= "</table>";
echo $msg;
}
}
}
/*
========================= 사용예제 =====================================
include "ClassDB_Hawk5_Mysql.php";
// 클래스 생성,
$db = new ClassDB_Hawk5_Mysql();
// 쿼리 실행
$query = "SELECT * FROM TB_Member ORDER ";
//실행후 오류가 있으면 출혁하고 없으면 총결과 갯수를 출력한다
if($db->Execute($query))
{
// 레코드 총합
echo "레코드 합계 : ";
echo $db->RecordCount();
}
else
{
// 오류가 있다면 출력
$db->ShowError();
exit;
}
// 레코드를 가져와서 출력
do {
echo $db->Field("UserId");
echo "<br>
[출처] 웹디황용
"쇼핑몰·홈페이지·오픈마켓
블로그·페이스북·이메일 등의 각종 마케팅 글쓰기, 각종 광고, 영업, 판매, 제안서, 전단지 반응율 3배×10배 이상 높이는 마법의 8단계 공식" |
☞자세히보기 |
|
|