我一直在這個問題上停留了大約一個小時,我無法解決它。請幫忙!奇怪的MySQL CREATE TABLE行爲
這裏是我的查詢:
CREATE TABLE IF NOT EXISTS snippets (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
code TEXT NOT NULL,
lang_id INT(3) UNSIGNED NOT NULL,
dev_id INT(11) UNSIGNED NOT NULL,
post_date TIMESTAMP NOT NULL DEFAULT NOW(),
views INT UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY (lang_id) REFERENCES languages (id),
FOREIGN KEY (dev_id) REFERENCES developers (id),
PRIMARY KEY (id)
);
這怎麼可能,這個查詢在phpMyAdmin,並在命令行上工作,但不是在PHP腳本?這是應該創建的6個表格中的第3個。前兩個完美的工作,但沒有任何後。任何幫助,將不勝感激。
$link = new PDOConfig();
$link->query("CREATE DATABASE IF NOT EXISTS ratemycode");
$link->connect($link, 'ratemycode');
$queries['tables'] = array(
"CREATE TABLE IF NOT EXISTS developers (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(42) NOT NULL,
password VARCHAR(64) NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
)",
"CREATE TABLE IF NOT EXISTS languages (
id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(42) NOT NULL,
PRIMARY KEY (id)
)",
"CREATE TABLE IF NOT EXISTS snippets (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
code TEXT NOT NULL,
lang_id INT(3) UNSIGNED NOT NULL,
dev_id INT(11) UNSIGNED NOT NULL,
post_date TIMESTAMP NOT NULL DEFAULT NOW(),
views INT UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY (lang_id) REFERENCES languages (id),
FOREIGN KEY (dev_id) REFERENCES developers (id),
PRIMARY KEY (id)
)",
"CREATE TABLE IF NOT EXISTS comments (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
body TEXT NOT NULL,
post_date TIMESTAMP NOT NULL DEFAULT NOW(),
snip_id INT(11) UNSIGNED NOT NULL,
dev_id INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (snip_id) REFERENCES snippets (id),
FOREIGN KEY (dev_id) REFERENCES developers (id),
PRIMARY KEY (id)
)",
"CREATE TABLE IF NOT EXISTS upvotes (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
snip_id INT(11) UNSIGNED NOT NULL,
dev_id INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (snip_id) REFERENCES snippets (id),
FOREIGN KEY (dev_id) REFERENCES developers (id),
PRIMARY KEY (id)
)",
"CREATE TABLE IF NOT EXISTS downvotes (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
snip_id INT(11) UNSIGNED NOT NULL,
dev_id INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (snip_id) REFERENCES snippets (id),
FOREIGN KEY (dev_id) REFERENCES developers (id),
PRIMARY KEY (id)
)"
);
foreach ($queries['tables'] as $table) {
$link->query($table);
}
什麼是錯誤信息? – Mihai
顯示你的php代碼 –
是什麼錯誤? – zzlalani