-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" when 実際にはそうではありませんが、データベースを削除して再作成しようとしましたが、成功しませんでした。誰かが助けることができれば、それは大歓迎です。ここに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がオフの場合は、オンにします。

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