시소당
class db_init {
var
$con;
var
$host;
var
$db;
var
$user;
var
$pass;
var
$error_message = "";
var
$error_flag = 0;
function db_init() {
global
$host,
$db,
$user,
$pass;
if (trim(
$host))
$this->host =
$host;
if (trim(
$db))
$this->db =
$db;
if (trim(
$user))
$this->user =
$user;
if (trim(
$pass))
$this->pass =
$pass;
$this->con = @mysql_connect(
$this->host,
$this->user,
$this->pass);
if (!
$this->con)
$this->db_error("DB연결오류");
if (!@mysql_select_db(
$this->db,
$this->con))
$this->db_error("DB선택오류");
}
function db_error(
$message) {
$this->error_flag++;
$this->error_message .= "<br>mysql_error ".mysql_errno()." |
$message<br><b>".mysql_error()."</b><br>";
}
}
일반적인 DB연결과 에러를 처리하는 클래스이다.