// connect to mysql
$db=mysql_connect('localhost','admin','password') or die('unable to connect');
//create the main database
$query='CREATE DATABASE IF NOT EXISTS moviesite11';
mysql_query($query,$db) or die(mysql_error($db));
mysql_select_db('moviesite',$db) or die(mysql_error($db));
//create movie table
$query='create table movie11
(
mov_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
mov_name VARCHAR(255) NOT NULL,
mov_type TINYINT NOT NULL DEFAULT 0,
mov_year SMALLINT UNSIGNED NOT NULL DEFAULT 0,
mov_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0,
mov_director INTEGER UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY(mov_id),
KEY mov_type(mov_type,mov_year)
)
ENGINE=MyISAM';
mysql_query($query,$db) or die(mysql_error($db));
//create the movietype table
$query='create table movie_type11
(
movtype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
movtype_label VARCHAR(255) NOT NULL,
PRIMARY KEY(movtype_id),
)
ENGINE=MyISAM';
mysql_query($query,$db) or die(mysql_error($db));
//create table people
$query='create table people11
(
people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
people_name VARCHAR(255) NOT NULL,
people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY(people_id),
)
ENGINE=MyISAM';
mysql_query($query,$db) or die(mysql_error($db));
echo 'Movie Database Successfully Created';
?>
why this code is showing error to me?????
Database ban rha hai magar error show kar rha hai
like
Unknown database 'moviesite'
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Sep 28, 2013, 1:02 AM
watch these lines of code:
---------------------------------------------------
-----------------------------------------------------------------------
Here you're creating a database named-"moviesite11", but you're trying to select a db named- "moviesite".
So, just try changing the first line as:
$query='CREATE DATABASE IF NOT EXISTS moviesite';
OR
the third line as:
mysql_select_db('moviesite11',$db) or die(mysql_error($db));
Hope it helps :)