[英]php mysql error for creating a table
I got an error while creating a table in php with mysql database, and I tried testing directly on mysql query engine it works fine. 我在使用mysql数据库的php中创建表时遇到错误,我尝试直接在mysql查询引擎上进行测试,效果很好。 whereas in php code it gives below error 而在PHP代码中,它给出了以下错误
You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near. 请查看与您的MySQL服务器版本相对应的手册,以在附近使用正确的语法。
Below is the code I am writing 下面是我正在编写的代码
$query14 = mysql_query("create table $tablename (
project_id INT,
project_client_id INT,
project_partner_id INT,
project_manager_id INT,
project_employees INT,
project_name VARCHAR(500),
project_status TEXT,
project_summary LONGTEXT,
project_order INT,
project_start_date DATETIME,
project_end_date DATETIME
) ENGINE = INNODB;");
and below is the image attached and table structure should be and this is the sample table i create using with phpmyadmin interface. 下面是图像和表结构,这是我通过phpmyadmin接口创建的示例表。 And below is the full error 下面是完整的错误
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 ''8' (project_id INT, project_client_id INT, project_partner_id INT, project_mana' at line 1`
I didn't see any problem with your query. 您的查询没有任何问题。 But what is the value of $tablename
? 但是$tablename
的值是什么? Two error possibilities here : 这里有两种可能的错误:
$tablename
is empty. 变量$tablename
为空。 $tablename
is a key-word. $tablename
是一个关键字。 Please check the above two otherwise its all right. 请检查以上两个,否则可以。
UPDATE : 更新:
As per your updated question please try with the following code. 根据您更新的问题,请尝试使用以下代码。 I think it will help you. 我认为它将为您提供帮助。
$query14 = mysql_query("create table `$tablename` (
`project_id` INT,
`project_client_id` INT,
`project_partner_id` INT,
`project_manager_id` INT,
`project_employees` INT,
`project_name` VARCHAR(500),
`project_status` TEXT,
`project_summary` LONGTEXT,
`project_order` INT,
`project_start_date` DATETIME,
`project_end_date` DATETIME
) ENGINE = INNODB;");
您的查询语法很好,看起来$ tablename为空。
I think the issue is what is getting replaced for $tablename. 我认为问题是$ tablename被替换了什么。
Having the full code example would be more useful in debugging the error. 拥有完整的代码示例将在调试错误时更加有用。
The mysql create statement works just fine here on mysql 5.1.58 . mysql create语句在mysql 5.1.58上可以正常工作。
As you said in above comments that after echoing the $tablename
you got the value 8
then it is not possible to create table. 正如您在上面的注释中所说的那样,在回显$tablename
您得到的值是8
那么就不可能创建表。
you have to rename the value of $tablename
like tbl_8
. 您必须像tbl_8
这样重命名$tablename
的值。
remember with the name tbl-8
your also got error,, 记住名称tbl-8
也会出错,
The problem is, $tablename is 8 currently and for SQL table, table name must start with a letter. 问题是,$ tablename当前为8,对于SQL表,表名必须以字母开头。 Current tablename is invalid. 当前表名无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.