<?
/* 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>";
?>