gpt4 book ai didi

php mysql建表报错

转载 作者:太空宇宙 更新时间:2023-11-03 10:23:30 24 4
gpt4 key购买 nike

我在使用 mysql 数据库在 php 中创建表时遇到错误,我尝试直接在 mysql 查询引擎上测试它工作正常。而在 PHP 代码中,它给出了以下错误

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.

下面是我写的代码

$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;");

下面是附加的图像和表结构,这是我使用 phpmyadmin 界面创建的示例表。下面是完整的错误

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`

enter image description here

最佳答案

我没有发现您的查询有任何问题。但是 $tablename 的值是多少?这里有两种错误可能性:

  1. 变量$tablename 为空。
  2. $tablename 是关键字。

请勾选以上两项否则没问题。

更新:

根据您更新的问题,请尝试使用以下代码。我认为它会对您有所帮助。

$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;");

关于php mysql建表报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8633688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com