dongpian6319 2014-02-11 22:45
浏览 39
已采纳

PHP / MYSQL:表未在wamp服务器中创建

when I run this php file in my wamp server it connects to database, selects database but not create table . the output is this:

connected to database succussfully.
connected to database store_db succussfully.
table users was not created.

what is the problem???

php code:

<?php
$sql='CREATE TABLE users
(
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID),
NAME CHAR(20),
PASSWORD CHAR(15),
)';

mysql_connect("localhost","root","") or die('could not connect to database.');
echo 'connected to database succussfully.<br>';

mysql_select_db('store_db') or die('database store_db not found.');
echo 'connected to database store_db succussfully.<br>';

mysql_query($sql) or die('table users was not created');
echo 'table users was created in database store_db succussfully.<br>';

?>
  • 写回答

4条回答 默认 最新

  • douwen1313 2014-02-11 22:49
    关注
    <?php
    $sql='CREATE TABLE users
    (
    PID INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(PID),
    NAME CHAR(20),
    PASSWORD CHAR(15),
    )';
    

    remove the comma after PASSWORD CHAR(15),

    in the event of an error, you can always retrieve errors using mysql_error().

    however. you should not be using the old mysql functions. much better and more secure options exist in the PDO and MySQLi extensions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 Mac(标签-IDE|关键词-File) idea
  • ¥15 潜在扩散模型的Unet特征提取
  • ¥15 iscsi服务无法访问,如何解决?
  • ¥15 感应式传感器制作的感应式讯响器