问题:应该通过$ wpdb-> insert将大量行插入数据库,但不会创建新行。
背景:
请帮忙!
<?php
function cb_t2c_cat_updater () {
global $wpdb;
$prefix = $wpdb->prefix;
//This is a truncated version of the valid SQL query, returns 178 rows
$cb_t2c_cat_update = $wpdb->get_results("SELECT
".$prefix."associations.object_id as 'object_id', ".$prefix."associations.term_taxonomy_id as 'taxo_id', ".$prefix."associations.term_id as 'term_id', ".$prefix."associations.cat_ID as 'cat_ID'
FROM ...
WHERE...
ORDER BY object_id ASC, term_id ASC, cat_ID ASC",ARRAY_A);
foreach ($cb_t2c_cat_update as $values) {
$table = $prefix . 'term_relationships';
$object_id = $values['object_id'];
$taxo_id = $values['taxo_id'];
$wpdb->insert(
$table,
array(
'object_id' => $object_id,
'term_taxonomy_id' => $taxo_id,
'term_order' => 0
),
array(
'%d',
'%d',
'%d',
)
);
}
}
add_action('init', 'cb_t2c_cat_updater');
?>
答案 0 :(得分:0)
有一个有效的解决方案 通过以下方式使变量整数:
$num_object_id = (int)$object_id
然后将这些传递给像:
这样的查询$wpdb->query("INSERT INTO... ")