글목록

2014. 2. 28.

PHP DB연동 테스트


$mysql_host     = 'localhost';
$mysql_user     = 'kickingplay';
$mysql_password = '천재';
$mysql_db       = 'db_kikcingplay';

//1. DB 연결
$connect = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die("MySQL cant'connect");
if(!$connect) echo "[success]
"; else echo "[Succees]
";

mysql_query(" SET NAMES UTF8 ");

//2. DB 선택
mysql_select_db($mysql_db, $connect);

//3. 쿼리 생성
$query = " select 'test' as string from dual ";

mysql_close($connect);

?>


PHP 5 신규연결 방식

$db_host = "localhost"; 
$db_user = "root"; 
$db_passwd = "test1234";
$db_name = "test"; 
$conn = mysqli_connect($db_host,$db_user,$db_passwd,$db_name);
if (mysqli_connect_errno($conn)) {
echo "데이터베이스 연결 실패: " . mysqli_connect_error();
} else {
echo "성공~!!!";
}
?>;

댓글 없음:

댓글 쓰기