gpt4 book ai didi

mysql - Codeigniter 模型出现错误 : Column count doesn't match value count at row 2

转载 作者:行者123 更新时间:2023-11-30 00:57:29 25 4
gpt4 key购买 nike

我正在从 rss.xml 源解析货币汇率,一切都很好。我现在尝试将该数据插入名为 rates 的数据库中,并使用名为 tblRates 的表。我不断收到此错误,但不知道为什么。这是我用来尝试批量插入数据库的模型中的函数。

function addIQDRates($Data){

if($this->db->insert_batch('tblRates', $Data, 'Currency'))
{
return $this->db->affected_rows();
}else{
return FALSE;
}
}

这里还有我在 Controller 中使用的 foreach 语句,用于对 xml 文件中的数据进行排序并将其插入数据库中。$Data = array();

$Data = array();
$Count = 0;

foreach ($xml->channel->item as $currencyInfo) {
$Data[$Count]['Currency'] = trim(str_replace("/USD", "", $currencyInfo->title)); // UNIQUE
$Data[$Count]['PubDate'] = date('Y-m-d H:i:s', strtotime(trim($currencyInfo->pubDate)));
$Data['CXRate'] = trim(preg_replace("/[^0-9,.]/", "", str_replace("1 United States Dollar = ", "", $currencyInfo->description)));
$Data[$Count]['DateCreated'] = date('Y-m-d H:i:s');
$Count++;
}

$TotalRows = $this->mycron_model->addIQDRates($Data);

这也是我的创建表语句

CREATE TABLE IF NOT EXISTS `tblRates` (
`RateID` int(11) NOT NULL AUTO_INCREMENT,
`Currency` varchar(50) NOT NULL,
`PubDate` datetime NOT NULL,
`CXRate` int(11) NOT NULL,
`DateCreated` datetime NOT NULL,
PRIMARY KEY (`RateID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

非常感谢所有帮助。

最佳答案

我不确定,您可能编写了 $Data['CXRate'] 而不是 $Data[$Count]['CXRate']

所以循环应该像下面这样:

foreach ($xml->channel->item as $currencyInfo) {
$Data[$Count]['Currency'] = trim(str_replace("/USD", "", $currencyInfo->title)); // UNIQUE
$Data[$Count]['PubDate'] = date('Y-m-d H:i:s', strtotime(trim($currencyInfo->pubDate)));
$Data[$Count]['CXRate'] = trim(preg_replace("/[^0-9,.]/", "", str_replace("1 United States Dollar = ", "", $currencyInfo->description)));
$Data[$Count]['DateCreated'] = date('Y-m-d H:i:s');
$Count++;
}

关于mysql - Codeigniter 模型出现错误 : Column count doesn't match value count at row 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20427509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com