SQL数据库设置问题

时间:2013-12-06 00:37:49

标签: php mysql

我正在尝试为简单的购物车应用设置数据库。我有一个create.php文件,应该建立表。我每次修复时都会遇到新的语法错误而且我不知道为什么。这是我的代码:

<?php
require_once 'conn.php';
$sql = <<<EOS
CREATE TABLE IF NOT EXISTS products (
    product_id int(4) NOT NULL auto_increment,
    price decimal(10,2) NOT NULL default '0.00',
    description varchar(255) NOT NULL default '',
    image_path varchar(255) NOT NULL default '',
    name varchar(30) NOT NULL default '',
    quantity int(4),
    long_description varchar(700) NOT NULL default '',
    PRIMARY KEY (product_id)
)
EOS;
$result = mysql_query($sql) or
    die(mysql_error());
    $sql = <<<EOS
    CREATE TABLE IF NOT EXISTS customers (
        customer_id int(11) NOT NULL auto_increment,
        first_name varchar(30) NOT NULL default '',
        last_name varchar(30) NOT NULL default '',
        suffix varchar(10),
        billing_address varchar(255) NOT NULL default '',
        shipping_address varchar(255) NOT NULL default '',
        email varchar(255),
        phone int(10) NOT NULL default '0000000000',
        password varchar(255) NOT NULL default '',
        PRIMARY KEY(customer_id)
    ) 
EOS;
$result = mysql_query($sql) or
    die(mysql_error());
    $sql = <<<EOS
    CREATE TABLE IF NOT EXISTS address (
        address_id int(20) NOT NULL auto_increment,
        address_line_1 varchar(50) NOT NULL default '',
        address_line_2 varchar(50),
        city varchar(40) NOT NULL default '',
        state char(2) NOT NULL default '',
        zip_code int(5) NOT NULL default '00000',
        PRIMARY KEY(address_id)
    )
EOS;
$result = mysql_query($sql) or
    die(mysql_error());
    $sql = <<<EOS
    CREATE TABLE IF NOT EXISTS orders (
        order_id int(11) NOT NULL auto_increment,
        customer_id int(11) NOT NULL,
        PRIMARY KEY(order_id),
        FOREIGN KEY(customer_id) REFERENCES customers(customer_id)
    )
EOS;
$result = mysql_query($sql) or
    die(mysql_error());
    $sql = <<<EOS
    CREATE TABLE IF NOT EXISTS cart_items (
        cart_id int(11) NOT NULL auto_increment,
        product_id int(4) NOT NULL default '',
        quantity int(5) NOT NULL default '',
        PRIMARY KEY(cart_id),
        FOREIGN KEY(product_id) REFERENCES products(product_id)

EOS;
$result = mysql_query($sql) or
    die(mysql_error());
echo "<html><head><h1>Tables created!!</h1></head></html>";

?>

这是我最新的错误:您的SQL语法出错了;查看与您的MySQL服务器版本相对应的手册,以便在第6行的''附近使用正确的语法。非常感谢任何帮助我指向正确方向的帮助。

0 个答案:

没有答案