SunTaag  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
PHP를 이용한 MySQL Database 생성

<?

/* Database 정보 */

$host = "localhost";

$user = "root";

$pass = "********";

$database = "experiment";

$tbl_tutor "subject";

/* MySQL 접속 */

$db = mysql_connect($host,$user,$pass) or die("서버 접속 에러 in create_table.php");

$sql "create database ".$database;

// 쿼리를 실행해서 결과값을 $result에 할당

$result = mysql_query($sql, $db);

if(!$result) // 데이터베이스 생성결과가 오류이면

{

echo "error) ".$sql."<br>";

echo mysql_errno()." : ".mysql_error()."<br>";

}

else

echo $database." 데이터베이스가 작성되었습니다.<br>";

echo "<br>";


/* Database 선택 */

mysql_select_db($database,$db);


/* 테이블 생성*/

$sql="create table ".$tbl_tutor."(".

"name text not null,".

"age int not null,".

"birth_year int not null,".

"gender varchar(1) not null,".

"address text not null,".

"phone text not null".

")";


// 쿼리를 실행해서 결과값을 $result에 할당

$result = mysql_query($sql, $db);

if(!$result) // 테이블 생성결과가 오류이면

{

echo "error) ".$sql."<br>";

echo mysql_errno()." : ".mysql_error()."<br>";

}

else

echo $tbl_tutor." 테이블이 작성되었습니다.<br>";

echo "<br>";


?>



BLOG main image
 Notice
 Category
분류 전체보기 (20)
Algorithm (3)
Signal Processing (0)
Programming (6)
Research (1)
Youtube (2)
ETC. (8)
 TAGS
 Calendar
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
 Recent Entries
 Recent Comments
 Archive
 Link Site
 Visitor Statistics
Total :
Today :
Yesterday :
rss