繁体   English   中英

我的插入代码有什么问题,出现意外错误?

[英]What is wrong with my Insert code it gets an unexpected error?

我想寻求您的帮助,我在插入中收到此error

Data truncated for column 'code' at row 1</p>
<p>INSERT INTO `permissions` (`employeeId`, `code`) VALUES ('2', '451</td');

我发现出了什么问题,这是“

这是我的php:

if (count($permissionsArray) > 0) {
            // Insert the new permissions to the database.
            $sSQL = "INSERT INTO `permissions` (`employeeId`, `code`) VALUES ";
            foreach ($permissionsArray as $item) {  
                $sSQL.= "('$eid', '$item'),";
            }
            $sSQL = substr($sSQL, 0, strlen($sSQL)-1).";";
            // Execute Query.
            $this->db->query($sSQL);
        }

您试图放入比列定义允许的更长的数据。 请提供您用于我们查看的查询。 此外谷歌搜索错误消息产生:

http://forums.mysql.com/read.php?11,132672,132672#msg-132672 http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html建议解决方案是修改服务器的“严格模式”设置:

当本手册提到“严格模式”时,它意味着至少启用了STRICT_TRANS_TABLESSTRICT_ALL_TABLES之一的模式。

如果问题是<td则可以使用strip_tags轻松解决

  $text = '451</td';
echo strip_tags($text);
echo "\n";

**OUTPUT** : 451

既然你提到<td是问题所在

I figured out whats wrong and it's the "</td" and that is unacceptable in my database. Does anyone knows how to remove that "</td". - **from question**

这是我的php:

if (count($permissionsArray) > 0) {
            // Insert the new permissions to the database.
            $sSQL = "INSERT INTO `permissions` (`employeeId`, `code`) VALUES ";
            foreach ($permissionsArray as $item) {  
                            $item = strip_tags($item);//removing html tag
                $sSQL.= "('$eid', '$item'),";
            }
            $sSQL = substr($sSQL, 0, strlen($sSQL)-1).";";
            // Execute Query.
            $this->db->query($sSQL);
        }

还要检查这个与您的问题相似的答案

为列 xxxx-at-row-1 截断的数据

mysql-data-truncated-for-column-advance-at-row-1

错误数据截断为列纬度在行 1

列的数据截断

从上面的链接中,我也建议您按照 kalp 在以下答案中的建议检查您的服务器模式设置

第 1 行第 XX 列的数据被截断

sql模式

暂无
暂无

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

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