我的问题是如此奇怪。 我想在mysql表中插入一行(使用InnoDB)。没有错误。一切都很好。但该行未添加到表中。Codeigniter 3插入查询失败
UPDATE:
从InnoDB的到的MyISAM更改表格引擎将解决这个问题,但为什么InnoDB的将无法正常工作?
这里是我的代码,它总是返回true:
$this->db->trans_start();
$this->db->set('userId', '27193');
$this->db->set('listId', '14');
$this->db->set('createDate', '2017-02-23');
$this->db->set('alertReq', '1');
$this->db->insert('parking');
if ($this->db->affected_rows() == '1') {
$this->db->trans_complete();
return true;
} else {
$this->db->trans_complete();
return false;
}
我也尝试以不同的方式插入查询:
$parkings = array (
'userId' => '27193',
'listId' => '14',
'createDate' => '2017-02-23',
'alertReq' => '1'
);
$this->db->trans_start();
$this->db->insert('parking', $parkings);
if ($this->db->affected_rows() == '1') {
$this->db->trans_complete();
return true;
} else {
$this->db->trans_complete();
return false;
}
OR
$sql = "INSERT INTO `parking` (`userId`, `listId`, `createDate`, `alertReq`) VALUES ('27193', '14', '2017-02-23', '1')";
$query = $this->db->query($sql);
在使用
$this->output->enable_profiler(TRUE);
在我的控制器,所有上述查询生成并显示:
INSERT INTO `parking` (`userId`, `listId`, `createDate`, `alertReq`) VALUES ('27193', '14', '2017-02-23', '1')
,即使在停车表,id列会自动递增探查& 1。 但目前还没有在加入新行表!!!
当我使用phpmyadmin或adminer插入该行时,它们按预期工作,我可以看到添加了新行。但与CI,我没有成功!
这里是我的表结构:
CREATE TABLE `parking` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userId` int(11) NOT NULL,
`listId` int(11) NOT NULL,
`createDate` date NOT NULL,
`alertReq` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
我试图删除停车表并重新创建它,但没有成功。 我也尝试创建另一张具有相同结构和不同名称的表(例如parkingsss),但是没有成功。
你已经在你的'配置/数据库启用错误报告.php“ – RiggsFolly
https://codeigniter.com/userguide3/database/transactions.html – RiggsFolly
是的。没有错误。我试过使用: $ this-> db-> trans_begin(); &$ this-> db-> trans_commit(); ,但没有成功 –