我正在使用dbDalta导入数据库中的这么多行。现在,我想检查所有行插入是否成功,受影响的行数和导入失败的行数。
我的代码:
$beginQuery = "INSERT INTO ".$wpdb->prefix."table_name(pzipcode, zip_class, pcity, pstate, lattitude, longitude, pcountry, pstatus, ptime, id) VALUES ";
$zips = array(
array(\'pzipcode\' => \'AB10\',\'latitude\' => \'57.13514\',\'longitude\' => \'-2.11731\',\'pcity\' => \'Aberdeen\',\'pstate\' => \'Scotland\',\'pcountry\' => \'SCT\'),
array(\'pzipcode\' => \'AB11\',\'latitude\' => \'57.13875\',\'longitude\' => \'-2.09089\',\'pcity\' => \'Aberdeen\',\'pstate\' => \'Scotland\',\'pcountry\' => \'SCT\'),
// ...................................
// ...................................
);
foreach($zips as $zip) {
//$beginQuery.\' (\'.$zip[\'zp\'].\',"\'.$zip[\'ct\'].\'","\'.$zip[\'st\'].\'","United States",1,"\'.current_time(\'mysql\', 1).\'")\';
$zipCodeDumper = dbDelta($beginQuery.\' ("\'.$zip[\'pzipcode\'].\'","\'.$zip[\'zip_class\'].\'","\'.$zip[\'pcity\'].\'","\'.$zip[\'pstate\'].\'","\'.$zip[\'lattitude\'].\'","\'.$zip[\'longitude\'].\'","\'.$zip[\'pcountry\'].\'","\'.$zip[\'pstatus\'].\'","\'.$zip[\'ptime\'].\'","\'.$zip[\'id\'].\'")\');
//break;
}
if (!$zipCodeDumper) {
echo "Successfully Imported all Zipcode/postcode.";
}else{
echo "Something was wrong!!! Please Try again";
}