我想使用 pdo 将海量数据添加到 mysql 数据库
我想更新大约 200 行数据,每行 10 个字段,我在下面使用了四个
连接到 db 很好,我测试了一些结果查询
字段使用 foreach 填充,这也很好,我验证了内容
但问题是执行功能,执行出错并且没有插入数据
请问怎么办,特此提供代码
//set db
$host = 'localhost';
$dbname = 'dbdata';
$attrs = array(PDO::ATTR_PERSISTENT => true);
$dbHandle = new PDO("mysql:host=$host;dbname=$dbname",'dbdatatable','tblpwd');
$dbHandle->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//===================================================
//prepare sql
$sql = "UPDATE TickersList SET field1=?, field2=?, field3=? WHERE field4=?";
$STH = $dbHandle->prepare($sql);
//===================================================
//declare arrays
$ufield1 = array();
$ufiled2 = array();
$ufiled3 = array();
$ufiled4 = array();
//===================================================
//fill arrays with data
foreach( $this->_data as $qty ){
$ufield1 [] = $qty->data1;
$ufield2 [] = $qty->data2;
$ufield3 [] = $qty->data3;
$ufield4 [] = $qty->data4;
}
//===================================================
//execute query - not working :(
$STH->execute($sql,$ufield1,$ufield2,$ufield3);
//===================================================