我已经在这个问题上停留了大约一个小时,但我无法解决它。请帮忙!
这是我的查询:
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);
}