从linux/apache迁移到IIs和codeigniter DB_driver.php给了我错误,我可以';我不再有空字段了?
我在Linux上使用apache。我移动到IIs服务器。 我正在运行codeigniter 2.0.0 我有一个带有activerecords的insert,它将表单中的数据插入数据库。数据库对每个字段都有默认值。这过去不是个问题。自从移动后,表单中的每个字段都必须填写,否则我会出现以下错误:从linux/apache迁移到IIs和codeigniter DB_driver.php给了我错误,我可以';我不再有空字段了?,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在Linux上使用apache。我移动到IIs服务器。 我正在运行codeigniter 2.0.0 我有一个带有activerecords的insert,它将表单中的数据插入数据库。数据库对每个字段都有默认值。这过去不是个问题。自从移动后,表单中的每个字段都必须填写,否则我会出现以下错误: Une erreur de base de données s'est produite. Error Number: 1292 Incorrect date value: '' for column
Une erreur de base de données s'est produite.
Error Number: 1292
Incorrect date value: '' for column 'DateNaissance' at row 1
INSERT INTO `patients` (`Nom`, `Prenom`, `Initial`, `Responsable`, `DateNaissance`) VALUES ('!teststef354', '!teststef9879', '', '0', '')
Filename: \system\database\DB_driver.php
Line Number: 330
可能我的codeigniter基本文件对于当前的php/mysql安装来说比较旧,所以我将一次升级一个版本。有办法解决这个问题吗
我在该服务器上运行了其他应用程序,但我还没有开发,比如MRB,它运行良好,我看到表中有空条目,没有任何问题
编辑:
这是我的模型
function add_patient($postdata)
{
$resultat=0;
if(!empty($postdata))
{
$resultat=$this->db->insert('patients',$postdata);
}
return $resultat;
}
在我的控制器中,我有:
$postdata = array (
'Nom'=> $_POST['Nom'],
'Prenom'=> $_POST['Prenom'],
'Initial'=> $_POST['Initial'],
'Responsable'=> $_POST['Responsable'],
'DateNaissance'=> $_POST['DateNaissance']
);
我将模型称为:
$patientsadd=$this->patients_model->add_patient($postdata);
编辑:在phpmyadmin中运行sql查询时出现了相同的错误。在mysql命令提示符下运行SQL查询也会出现同样的错误,因此这是mysql的问题
下面是该表的Create语句:
CREATE TABLE IF NOT EXISTS `patients` (
`IdPatient` int(11) NOT NULL AUTO_INCREMENT,
`Nom` varchar(50) DEFAULT NULL,
`Prenom` varchar(50) DEFAULT NULL,
`Initial` varchar(4) DEFAULT NULL,
`Responsable` int(11) DEFAULT '0',
`DateNaissance` date DEFAULT '0000-00-00',
PRIMARY KEY (`IdPatient`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=397 ;
编辑:好,这样就可以了:
这就是我所做的。我确实有更多的字段,但出于提问的目的,我缩短了它
所有文本字段都可能有问题,因此我将对它们进行编辑。至少这样,我不会向模型传递一个空值,MySQL也不会因此而窒息。它的文本字段有默认的空值(希望如此),所以这应该可以解决这个错误
$postdata = array();
$postdata['Nom'] = $_POST['Nom'];
$postdata['Prenom'] = $_POST['Prenom'];
$postdata['Initial'] = $_POST['Initial'];
$postdata['Responsable'] = $_POST['Responsable'];
if (isset($_POST['DateNaissance']))
{}else {$postdata['DateNaissance'] = $_POST['DateNaissance']; }
感谢所有的评论者帮助我找出问题的根源
我还是觉得我有问题,我犯了个错误
本部分:
if (isset($_POST['DateNaissance']))
{}else {$postdata['DateNaissance'] = $_POST['DateNaissance']; }
应该是:
if (empty($_POST['DateNaissance']))
{}else{$postdata['DateNaissance'] = $_POST['DateNaissance']; }
您可以将控制器信息更改为:
$postdata = array (
'Nom'=> $_POST['Nom'],
'Prenom'=> $_POST['Prenom'],
'Initial'=> $_POST['Initial'],
'Responsable'=> $_POST['Responsable'],
'DateNaissance'=> ($_POST['DateNaissance']=='') ? 0 : $_POST['DateNaissance'];
);
请参阅,这将删除错误-我收到(更改前)的错误消息
'第1行'DateNaissance'列的数据被截断'如果尝试手动运行查询会发生什么情况?因为您使用的是Active Record,插入时使用的代码是什么?我用模型和控制器数据更新了代码。cWallenPole:在phpmyadmin中手动输入该查询会产生完全相同的错误,因此,我认为它与codeigniter无关…aaa并将其运行到mysql的命令提示符中,会出现完全相同的错误。。。那么我如何在mysql中修复这个问题呢?我的字段有默认值…谢谢,这是一种方法。至少我找出了导致错误的原因。在它起作用之前,但我想这不是最好的做法!