尝试在 CodeIgniter Active reacords 的帮助下插入一个数组。表只有两列id(autoincrement pk column)
和value
.
我从 Google Contact API 响应中填充的 $data 数组。在这里,我如何在控制器中填充数组 $data 并将其传递给模型
$val = $client->getIo()->authenticatedRequest($req);//Getting response from Google Contact API.
$xml = simplexml_load_string($val->getResponseBody());
$result = $xml->xpath('//gd:email'); //Fetching email addressed from the response
foreach ($result as $title) {
array_push($gmailContacts, mysql_real_escape_string($title->attributes()->address));
}
$this->load->model('gmailContacts');
$this->gmailContacts->saveContacts($gmailContacts);
型号代码是
function saveGmailContacts($data=array())
{
$this->db->insert('contact_table',$data);
}
错误是
Error Number: 1054
Unknown column '0' in 'field list'
INSERT INTO `importedgmailcontacts` (`0`, `1`, `2`, `3`, `4`, `5`)VALUES ('VALUE1', 'VALUE2', 'VALUE3','VALUE4', 'VALUE5')
我正在将 Codeigniter 与 XAMPP 1.7.7 一起使用,它具有 PHP 5.3.3 和 MySql 5.0