-1

我有一个小的 php 文件,它只是在数据库中创建表。我花了几天时间尝试调试它,这让我很困惑。HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.当我执行查询时,它会很丑。但是,当我打印出查询并将它们粘贴到数据库中时,它工作正常。

我还注意到手动输入查询时“表已存在”会闪烁,但会消失并快速工作。类似于这个问题Mysql 1050 Error "Table already exists" 实际上它没有,但我尝试删除并重新制作数据库但没有成功。如果有人可以提供帮助,将不胜感激。这是php代码

$users = 'CREATE TABLE users (
        id int UNSIGNED NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(id),
        username varchar(30) NOT NULL, UNIQUE(username),
        password varchar(30) NOT NULL,
        email varchar(50) NOT NULL, UNIQUE(email),
        confirmation_code int NOT NULL,
        confirmation_tries int NOT NULL
    ) ENGINE=InnoDB';

$players = 'CREATE TABLE players (
        id int UNSIGNED NOT NULL,
        FOREIGN KEY(id) REFERENCES users(id),
        cost int UNSIGNED NOT NULL,
        strategy TINYINT UNSIGNED NOT NULL,
        age int UNSIGNED NOT NULL,
        %s
    ) ENGINE=InnoDB';
$records = array();
for ($i = 0; $i < NUM_RECORDS; $i++) {
    $records[$i] = sprintf('record_%d int UNSIGNED NOT NULL', $i);
}
$players = sprintf($players, implode(', ', $records));

$kingdoms = 'CREATE TABLE kingdoms (
        id int UNSIGNED NOT NULL,
        FOREIGN KEY(id) REFERENCES users(id),
        location int UNSIGNED NOT NULL,
        building text NOT NULL,
        level int UNSIGNED NOT NULL,
        troops int UNSIGNED NOT NULL
    ) ENGINE=InnoDB';

$inboxes = 'CREATE TABLE inboxes (
        recipientID int UNSIGNED NOT NULL,
        FOREIGN KEY(recipientID) REFERENCES users(id),
        messageID int UNSIGNED NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(messageID),
        message text NOT NULL,
        date DATETIME NOT NULL
    ) ENGINE=InnoDB';

$lastActions = 'CREATE TABLE last_actions (
        id int UNSIGNED NOT NULL,
        FOREIGN KEY(id) REFERENCES users(id),
        history text
    ) ENGINE=InnoDB';

$news = 'CREATE TABLE news (
        id int UNSIGNED NOT NULL,
        FOREIGN KEY(id) REFERENCES users(id),
        entries text
    ) ENGINE=InnoDB';

/*
$dbh->exec($users);
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '111111';
    exit;
}
$dbh->exec($players);
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '22222';
    exit;
}
$dbh->exec($kingdoms);
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '33333';
    exit;
}
$dbh->exec($inboxes);
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '44444';
    exit;
}
$dbh->exec($lastActions);
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '555555';
    exit;
}
$dbh->exec($news);//
$code = $dbh->errorCode();
if ($code !== '00000') {
    var_dump($code);
    echo '666666';
    exit;
}//*/
echo $users . ";" . $players . ";" . $kingdoms . ';' . $inboxes . ';' . $lastActions .';' . $news;
4

1 回答 1

1

HTTP 错误 500(内部服务器错误)是 HTTP 请求的错误响应。
使用mysql_error或您使用的任何内容来回显mysql_query的响应以获取错误。或检查 error_logs。它不完全由mysql返回。

如果您的 error_reporting 已关闭,请将其设为 ON。

error_reporting( E_ALL | E_STRICT ); 
ini_set( 'display_errors', 1 )
于 2012-06-23T07:43:02.340 回答