简体   繁体   English

Alter表的MySQL 1064错误

[英]MySQL 1064 error for alter table

This is driving me nuts, I can't figure out what's wrong. 这让我发疯,我不知道怎么了。

Here is the query passed in mysqli_query: 这是在mysqli_query中传递的查询:

ALTER TABLE `lc_products` ADD `default_category_id` int(11) NOT NULL AFTER `sold_out_status_id`;

This is the fatal error that PHP throws: 这是PHP引发的致命错误:

Fatal error: 1064 - 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 'ALTER TABLE `lc_products` ADD `default_category_id` int(11) NOT NULL AFTER `s' at line 1

The exact same query works when inserted into phpMyAdmin. 当插入phpMyAdmin中时,完全相同的查询有效。

Using XAMP for Windows with PHP 5.4 + MySQL 5.5.4. 将XAMP for Windows与PHP 5.4 + MySQL 5.5.4结合使用。

Does anyone know what's going on, or what is wrong? 有谁知道发生了什么事或出了什么问题?

$query = "ALTER TABLE `lc_products` ADD `default_category_id` int(11) NOT NULL AFTER `sold_out_status_id`;";
$result = mysqli_query($link, $query) or $this->_error($query, mysqli_errno($link), mysqli_error($link));

Delete the semi-colon from your query. 从查询中删除分号。

 $query = "ALTER TABLE `lc_products` ADD `default_category_id` int(11) 
           NOT NULL AFTER `sold_out_status_id`";

Illegal byte character. 非法字节字符。

I used var_dump() to debug the query string and discovered a hidden Byte Order Mark character (UTF-8 BOM) that was not supposed to be there. 我使用var_dump()调试查询字符串,并发现了一个不应存在的隐藏的字节顺序标记字符(UTF-8 BOM)。 The debug indicated a string length longer than expected. 调试指示字符串长度比预期的长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM