±×·³ Àú ¹Ø¿¡ ¼Ò½º¿¡¼ Á¦°¡ °íÃľßÇϴºκи¸ »ö°¥·Î Ç¥½Ã¸¦ ÇØ ÁֽǼö´Â ¾ø³ª¿ä? ¸¸¾à¿¡ db°¡ 1ÀÌ°í dbºñ¹øÀÌ2¶ó°í°¡Á¤Çϱ¸¿ä... Á¦°¡ Ãʺ¸¶ó ¿°Ä¡ºÒ±¸ÇÏ°í ºÎŹÀ» µå¸²´Ï´Ù...
<?
// ÀÛ¼ºÀÚ : ÃÖ»ó¹Î
// ¼öÁ¤ÀÏ : 2002³â 2¿ù 17ÀÏ
// ÆÄÀϸí : dbConnect.php
// µ¥ÀÌÅÍ º£À̽º ¿¬°á Ŭ·¡½º
class dbConnect {
var $host;
var $user;
var $pass;
var $db;
var $conn = false;
// ÀϹݿ¬°áÀ» À§ÇÑ »ý¼ºÀÚ
function dbConnect($host, $user, $pass, $db) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->db = $db;
$this->conn = mysql_connect($host, $user, $pass) or die("MySQL¿¬°á¿¡ ½ÇÆÐÇß½À´Ï´Ù. °ü¸®ÀÚ¿¡°Ô ¹®Àǹٶø´Ï´Ù.");
if(!mysql_select_db($db, $this->conn)) {
echo "µ¥ÀÌÅÍ º£À̽º ¿¬°á¿¡ ÀÌ»óÀÌ ÀÖ½À´Ï´Ù. °ü¸®ÀÚ¿¡°Ô ¹®Àǹٶø´Ï´Ù.";
exit();
}
return 1;
}
// Ä¿³Ø¼Ç °¡Á®¿À±â
function getConnection() {
return $this->conn;
}
function runQuery($query) {
if($this->conn)
return mysql_query($query, $this->conn);
else {
echo "µ¥ÀÌÅÍ º£À̽º ¿¬°áÀ» ÇÏÁö ¾Ê¾Ò½À´Ï´Ù.";
exit();
}
}
// µ¥ÀÌÅͺ£À̽º ´Ý±â
function closeConnection() {
return mysql_close($this->conn)?1:0;
}
}
//================================== »ç¿ëÀÚÀÇ È¯°æ¿¡ ¸Â°Ô ¹Ýµå½Ã ¼öÁ¤ÇØÁֽʽÿä ====================================================//
$host = "localhost"; // Host
$user = "sad2sang"; // User
$pass = "sad2sang"; // Password
$db = "sad2sang"; // Database
$conn = new dbConnect($host, $user, $pass, $db);
?>