简单的PHP/MySQL创建表脚本 [英] Simple PHP/MySQL Create Table Script
问题描述
因此,我拥有此脚本仅用于在数据库中创建表.我已经从一个旧脚本中复制了该脚本,该脚本现在可以正常工作.为什么这个不起作用?任何人?
So I have this script just to create a table in my database. I've copied it over from an old script I did that is working right now. How come this one is not working? Anyone?
我遇到的错误是"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "'= varchar (20) NOT NULL, column_two = int NOT NULL auto_increment, column_thre' at line 2"
<?php
include("server_connect.php");
mysql_select_db("assignment5");
$create = "CREATE TABLE tbltable (
column_one = varchar (20) NOT NULL,
column_two = int NOT NULL auto_increment,
column_three = int NOT NULL,
column_four = varchar (15) NOT NULL,
column_five = year,
PRIMARY KEY = (column_one)
)";
$results = mysql_query($create) or die (mysql_error());
echo "The tables have been created";
?>
推荐答案
按照建议删除所有=
:
$create = "CREATE TABLE tbltable (
column_one varchar (20) NOT NULL,
column_two int NOT NULL auto_increment PRIMARY KEY,
column_three int NOT NULL,
column_four varchar (15) NOT NULL,
column_five year
)";
每个表都应具有主键,并且您必须将AUTO_INCREMENT
列指定为PRIMARY KEY
.在这种情况下,AUTO_INCREMENT
列为column_two
,我将其设置为PRIMARY KEY
.
Each and every table should have a primary key and you must specify AUTO_INCREMENT
column as PRIMARY KEY
. In this case, the AUTO_INCREMENT
column is column_two
and I've set that as the PRIMARY KEY
.
这篇关于简单的PHP/MySQL创建表脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!