简体   繁体   English

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

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

I would like to ask for your help, I have recieving this error in my insert.我想寻求您的帮助,我在插入中收到此error

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

I figured out whats wrong and it's the "我发现出了什么问题,这是“

Here is my php:这是我的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);
        }

You tried to put in data that was longer than what your column definitions allow.您试图放入比列定义允许的更长的数据。 Please provide the queries you used for us to see.请提供您用于我们查看的查询。 In addition googling the error message yielded:此外谷歌搜索错误消息产生:

http://forums.mysql.com/read.php?11,132672,132672#msg-132672 http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html The suggested solution there is to modify the server's "strict mode" setting:http://forums.mysql.com/read.php?11,132672,132672#msg-132672 http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html建议解决方案是修改服务器的“严格模式”设置:

When this manual refers to “strict mode,” it means a mode where at least one of STRICT_TRANS_TABLES or STRICT_ALL_TABLES is enabled.当本手册提到“严格模式”时,它意味着至少启用了STRICT_TRANS_TABLESSTRICT_ALL_TABLES之一的模式。

If the problem is <td then it can easily be solved using strip_tags如果问题是<td则可以使用strip_tags轻松解决

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

**OUTPUT** : 451

Since you have mentioned <td is the problem既然你提到<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**

Here is my php:这是我的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);
        }

Also check this answer which is similar to your problem还要检查这个与您的问题相似的答案

data-truncated-for-column-xxxx-at-row-1为列 xxxx-at-row-1 截断的数据

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

error-data-truncated-for-column-lat-at-row-1错误数据截断为列纬度在行 1

Data truncate for coloumn列的数据截断

from above links I too would suggest you to check your server mode settings as suggested by kalp in below answer从上面的链接中,我也建议您按照 kalp 在以下答案中的建议检查您的服务器模式设置

data truncated for column XX at row 1第 1 行第 XX 列的数据被截断

sql-mode sql模式

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

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