2013-10-31 124 views
0

我試圖用4個表創建一個數據庫。當我運行我的代碼時,它會創建第一個表,但不會創建第三個表。這是因爲第二個表沒有將存儲引擎更改爲myISAM,但我無法弄清楚爲什麼它沒有這樣做。這裏是我的代碼:SQL數據庫問題

<?php 
require_once 'conn.php'; 
$sql= <<<EOS 
CREATE TABLE IF NOT EXISTS cms_access_levels (
    access_lvl tinyint(4) NOT NULL auto_increment, 
    access_name varchar(50) NOT NULL default'', 
    PRIMARY KEY(access_lvl) 
) 
EOS; 
    $result= mysql_query($sql) or 
    die(mysql_error()); 
$sql= "INSERT IGNORE INTO cms_access_levels " . 
    "VALUES(1, 'Users'), " . 
    "(2, 'Moderator'), " . 
    "(3, 'Administrator')"; 
$result= mysql_query($sql) or 
    die(mysql_error()); 
$sql= <<<EOS 
CREATE TABLE IF NOT EXISTS cms_articles ENGINE = MYISAM (
    article_id int(11) NOT NULL auto_increment, 
    author_id int(11) NOT NULL default '0', 
    is_published tinyint(11) NOT NULL default '0', 
    date_submitted datetime NOT NULL default '0000-00-00 00:00:00', 
    date_published datetime NOT NULL default '0000-00-00 00:00:00', 
    title varchar(255) NOT NULL default '', 
    body mediumtext NOT NULL, 
    PRIMARY KEY(article_id), 
    KEY IdxArticle(author_id, date_submitted), 
    FULLTEXT KEY IdxText(title, body) 
) 
    EOS; 
$result= mysql_query($sql) or 
    die(mysql_error()); 
    $sql= <<<EOS 
    CREATE TABLE IF NOT EXISTS cms_comments (
     comment_id int(11) NOT NULL auto_increment, 
     article_id int(11) NOT NULL default '0', 
     comment_date datetime NOT NULL default '0000-00-00 00:00:00', 
     comment_user int(11) NOT NULL default '0', 
     comment text NOT NULL, 
     PRIMARY KEY(comment_id), 
     KEY idxComment(article_id) 
) 
    EOS; 
$result= mysql_query($sql) or 
    die(mysql_error()); 
    $sql= <<<EOS 
    CREATE TABLE IF NOT EXISTS cms_users (
    user_id int(11) NOT NULL auto_increment, 
    email varchar(255) NOT NULL default '', 
    password varchar(50) NOT NULL default '', 
    name varchar(100) NOT NULL default '', 
    access_lvl tinyint(4) NOT NULL default '1', 
    PRIMARY KEY(user_id), 
    UNIQUE KEY uniq_email(email) 
) 
    EOS; 
$result= mysql_query($sql) or 
    die(mysql_error()); 
$adminemail= "[email protected]"; 
$adminpass= "graysen7"; 
$adminname= "olle"; 
$sql= "INSERT INTO cms_users " . 
"VALUES (NULL, '$adminemail', '$adminpass', '$adminname', 3)"; 
$result= mysql_query($sql) or 
    die(mysql_error()); 
echo "<html><head><title>CMS Tables Created</title></head><body>"; 
echo "CMS Tables created. Here is the initial login information: <br />"; 
echo "<ul><li><strong>Login:</strong> " . $adminemail . "</li><br />"; 
echo "<li><strong>Password:</strong> " . $adminpass . "</li><br />"; 
echo "<a href='login.php'>Login</a> to the site now."; 
echo "</ul></body></html>"; 
    ?> 

任何幫助,不勝感激!

回答

1

據我所知,我的數據庫告訴我我是對的,引擎應該在創建定義後提及。試試這個:

CREATE TABLE IF NOT EXISTS cms_articles (
    article_id int(11) NOT NULL auto_increment, 
    author_id int(11) NOT NULL default '0', 
    is_published tinyint(11) NOT NULL default '0', 
    date_submitted datetime NOT NULL default '0000-00-00 00:00:00', 
    date_published datetime NOT NULL default '0000-00-00 00:00:00', 
    title varchar(255) NOT NULL default '', 
    body mediumtext NOT NULL, 
    PRIMARY KEY(article_id), 
    KEY IdxArticle(author_id, date_submitted), 
    FULLTEXT KEY IdxText(title, body) 
) ENGINE = MYISAM 
+0

非常好!這就是我需要的,謝謝! –