웹마스터 팁
page_full_width">
MYSQL CLASS
2002.12.03 14:59
흠..용도는 MYSQL 쿼리를 편하게 날리고자 하는것도 아닙니다.
단지 인스턴스 생성으로 인한 편리함과
프로그래밍상 디버깅?을 위해서 입니다.
자 잘 보시면 알겠지만
$co = new mysql;
$co->dbconn('','','','');
$co->query('쿼리');
를 하면..쿼리가 저장되서 로깅됩니다.
나중에
$co->print_query();
해주면 여태까지 쓴 쿼리문들이 쭉 출력됩니다.
뭐 저는 저정도 기능이면 만족하므로...저렇게 씁니다.
필요하시면 추가하셔도 되구요.
아참 time_now() 라는 함수는 그냥 현재 시간을 구하는겁니다.
그럼 ^-^
class mysql {
var $conn = FALSE;
var $querys;
var $times;
function dbconn($id,$pw,$host,$db) {
$this->conn = mysql_connect($host,$id,$pw);
mysql_select_db($db,$this->conn);
if($this->conn) return 1;
if(!$this->conn) return 0;
}
function close() {
mysql_close($this->conn);
}
function query($query) {
$a1 = time_now();
$result = mysql_query($query,$this->conn);
$a2 = time_now();
$this->times += $a2-$a1;
$this->querys .= "▶Query:".$query."<br>";
return $result;
}
function fetch_array($results) {
$result = @mysql_fetch_array($results);
return $result;
}
function result($result,$f) {
return @mysql_result($result,0,$f);
}
function num($result) {
$temp = @mysql_fetch_row($result);
return $temp[0];
}
function print_query() {
return $this->querys.$this->times;
}
}
단지 인스턴스 생성으로 인한 편리함과
프로그래밍상 디버깅?을 위해서 입니다.
자 잘 보시면 알겠지만
$co = new mysql;
$co->dbconn('','','','');
$co->query('쿼리');
를 하면..쿼리가 저장되서 로깅됩니다.
나중에
$co->print_query();
해주면 여태까지 쓴 쿼리문들이 쭉 출력됩니다.
뭐 저는 저정도 기능이면 만족하므로...저렇게 씁니다.
필요하시면 추가하셔도 되구요.
아참 time_now() 라는 함수는 그냥 현재 시간을 구하는겁니다.
그럼 ^-^
class mysql {
var $conn = FALSE;
var $querys;
var $times;
function dbconn($id,$pw,$host,$db) {
$this->conn = mysql_connect($host,$id,$pw);
mysql_select_db($db,$this->conn);
if($this->conn) return 1;
if(!$this->conn) return 0;
}
function close() {
mysql_close($this->conn);
}
function query($query) {
$a1 = time_now();
$result = mysql_query($query,$this->conn);
$a2 = time_now();
$this->times += $a2-$a1;
$this->querys .= "▶Query:".$query."<br>";
return $result;
}
function fetch_array($results) {
$result = @mysql_fetch_array($results);
return $result;
}
function result($result,$f) {
return @mysql_result($result,0,$f);
}
function num($result) {
$temp = @mysql_fetch_row($result);
return $temp[0];
}
function print_query() {
return $this->querys.$this->times;
}
}