用于创建表的 PHP 脚本
我需要创建 MySQL 表。所以我正在运行这个脚本,但它不起作用。知道为什么吗?
<?php
$con = mysql_connect("database.dcs.aber.ac.uk","xxx","nnnnnnnnnn");
mysql_select_db("jaz",$con);
$sql = "CREATE TABLE storys
(
id int NOT NULL AUTO_INCREMET,
title TINYTEXT,
type TINYTEXT,
link TEXT,
preview TINYTEXT,
tags TINYTEXT,
text MEDIUMTEXT,
updated TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP,
created DATETIME() DEFAULT NULL,
PRIMARY KEY(id)
)";
mysql_query($sql,$con);
mysql_close($con);
?>
I need to create MySQL table. So I'm running this script but it's just not working. Any idea why?
<?php
$con = mysql_connect("database.dcs.aber.ac.uk","xxx","nnnnnnnnnn");
mysql_select_db("jaz",$con);
$sql = "CREATE TABLE storys
(
id int NOT NULL AUTO_INCREMET,
title TINYTEXT,
type TINYTEXT,
link TEXT,
preview TINYTEXT,
tags TINYTEXT,
text MEDIUMTEXT,
updated TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP,
created DATETIME() DEFAULT NULL,
PRIMARY KEY(id)
)";
mysql_query($sql,$con);
mysql_close($con);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码绝对没有错误处理,这会向您显示查询失败的原因。
是您在几乎每个 mysql 调用中都应该进行的最低限度的错误处理。
如果这是适当的,你必须被告知:
Your code has absolute NO error handling, which would have shown you the reason the query's failing.
is the bare minimum error handling you should have on pretty much every mysql call.
Had this been in place, you'd have to been told:
在前面列出的问题中,您在数据类型定义中使用函数,并且“ON UPDATE”语法是错误的。
我认为您在 SQL 中寻找的内容如下:
Among the previously listed issues, you are using functions in the data type definitions, and the "ON UPDATE" syntax is wrong.
Here is what I think you are looking for in the SQL: