Monday, November 5, 2012

zend framework–error log -SQLSTATE[HY093]

php code:

        $data = array();
// $this->_db->beginTransaction();
foreach($id2img as $pid => &$thumbnails){
foreach($thumbnails as &$thumbnail){
$result = $this->fetchRow("url = '" . $thumbnail['url'] . "'");
if($result['url'])
continue;
$thumbnail['pid'] = $pid;
$thumbnail['ptype'] = 1;
//$this->insert($thumbnail);

$thumbnail['id'] = null;
$data []= $thumbnail;
}
}
//$this->_db->commit();

$sql = 'INSERT INTO ' . $this->_name . ' (' . implode(',',array_keys($data[0])) . ') VALUES ' . implode(',',array_fill(0,count($data),'(' . implode(',',array_fill(0,count($data[0]),'?')) . ')'));
$stmt = $this->getAdapter()->prepare($sql);
//echo($sql);print_r($data);exit();
$stmt->execute( $data );



error:


An error occurred

Application error

Exception information:

Message: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Stack trace:

#0 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Db\Statement.php(303): Zend_Db_Statement_Pdo->_execute(Array)
#1 D:\doc\webserver\wwwroot\mw\application\modules\m\models\ImageModel.php(41): Zend_Db_Statement->execute(Array)
#2 D:\doc\webserver\wwwroot\mw\application\modules\m\models\RssItemModel.php(451): ImageModel->InsertRssImages(291, Array)
#3 D:\doc\webserver\wwwroot\mw\application\modules\m\models\RssItemModel.php(250): RssItemModel->_parsedownloaditem(291, '2012-11-05 12:2...')
#4 D:\doc\webserver\wwwroot\mw\application\modules\m\models\RssItemModel.php(57): RssItemModel->_downloadnewitem(291)
#5 D:\doc\webserver\wwwroot\mw\application\modules\m\models\RssItemModel.php(98): RssItemModel->getNewItem(291, 0, 20, 0, '1')
#6 D:\doc\webserver\wwwroot\mw\application\modules\m\controllers\RssajaxController.php(464): RssItemModel->getTotalItem('2', '1', '291', '0', '0', '20', 0, '1')
#7 D:\doc\webserver\wwwroot\mw\application\modules\m\controllers\RssajaxController.php(863): M_RssajaxController->rssfulllistAction()
#8 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Action.php(516): M_RssajaxController->getAction()
#9 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action->dispatch('getAction')
#10 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#11 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#12 E:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#13 D:\doc\webserver\wwwroot\mw\public\index.php(43): Zend_Application->run()
#14 {main}
Request Parameters:

array (
'module' => 'm',
'controller' => 'rssajax',
'action' => 'get',
'task' => 'rssfulllist',
'lid' => '2',
'cid' => '1',
'tid' => '291',
'iid' => '0',
'start' => '0',
'limit' => '20',
'picmode' => '1',
)


resolved:

foreach($id2img as $pid => &$thumbnails){
foreach($thumbnails as &$thumbnail){
$result = $this->fetchRow("url = '" . $thumbnail['url'] . "'");
if($result['url'])
continue;
$thumbnail['pid'] = $pid;
$thumbnail['ptype'] = 1;
$this->insert($thumbnail);

//foreach($thumbnail as $k => &$v){
// $data []= $v;
//}
}
}



 


No comments: