注意:#1265数据在第1行的“开始”列被截断

时间:2015-08-10 12:49:21

标签: php mysql phpmyadmin

我为名为poll的投票应用程序和名为pollsusers的表创建了一个数据库。

当我为第二个问题添加SQL时:

INSERT INTO `poll`.`polls` (`id`, `question`, `starts`, `ends`) VALUES ('2', 'What''s your favourite web language?', NOW(), '2015-08-12');

标题出现警告。这是出口:

-- phpMyAdmin SQL Dump
-- version 4.2.12deb2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 10, 2015 at 02:46 PM
-- Server version: 5.5.44-0+deb8u1
-- PHP Version: 5.6.9-0+deb8u1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `poll`
--

-- --------------------------------------------------------

--
-- Table structure for table `polls`
--

CREATE TABLE IF NOT EXISTS `polls` (
`id` int(11) unsigned NOT NULL,
  `question` text,
  `starts` date DEFAULT NULL,
  `ends` date DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `polls`
--

INSERT INTO `polls` (`id`, `question`, `starts`, `ends`) VALUES
(1, 'What do you think about new whey protein?', '2015-08-10', '2015-08-12'),
(2, 'What''s your favourite web language?', '2015-08-10', '2015-08-12');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `polls`
--
ALTER TABLE `polls`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `polls`
--
ALTER TABLE `polls`
MODIFY `id` int(11) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

是否由第二个问题引起了撇号?

编辑:这不重复,因为我在phpMyAdmin中这样做,我知道什么是SQL注入:)

2 个答案:

答案 0 :(得分:1)

Whats之间有两个单引号,如What''s

尝试

INSERT INTO `poll`.`polls` (`id`, `question`, `starts`, `ends`) VALUES ('2', 'What\'s your favourite web language?', NOW(), '2015-08-12');+

而不是

INSERT INTO `poll`.`polls` (`id`, `question`, `starts`, `ends`) VALUES ('2', 'What''s your favourite web language?', NOW(), '2015-08-12');

注意在PHP代码中使用addslashes()可以解决此类问题。

答案 1 :(得分:0)

尝试考虑sql_modes。它可以控制MySQL如何处理错误。

您可以将session sql_mode设置为:

SET SESSION sql_mode = 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES'

original post还告诉您如何使其持久化。