我正在尝试插入和更新数据但它似乎在wordpress中不起作用。数据库存在,当我尝试手动插入它时,它可以工作。
global $wpdb;
$db=$wpdb->prefix.'arete_woocommerce_sms_panel_settings';
$data = $wpdb->get_results ("SELECT * FROM {$db}");
if (!empty( $data )) {
$wpdb->update("{$db}",array('type'=>"sms_provider_url",'value'=>$sms_provider_url),array('%s','%s'));
$wpdb->update("{$db}",array('type'=>"sms_provider_username_with_param",'value'=>$username),array('%s','%s'));
$wpdb->update("{$db}",array('type'=>"sms_provider_password_with_param",'value'=>$password),array('%s','%s'));
$wpdb->update("{$db}",array('type'=>"sms_provider_key_with_param",'value'=>$sms_api_key_with_parameter),array('%s','%s'));
$wpdb->update("{$db}",array('type'=>"sms_provider_sender_id_with_param",'value'=>$sms_api_sender_id_with_parameter),array('%s','%s'));
$wpdb->update("{$db}",array('type'=>"sms_provider_custom_with_param",'value'=>$sms_custom_values_with_parameter),array('%s','%s'));
}
else
{
$wpdb->insert("{$db}",array('type'=>"sms_provider_url",'value'=>$sms_provider_url),array('%s','%s'));
$wpdb->insert("{$db}",array('type'=>"sms_provider_username_with_param",'value'=>$username),array('%s','%s'));
$wpdb->insert("{$db}",array('type'=>"sms_provider_password_with_param",'value'=>$password),array('%s','%s'));
$wpdb->insert("{$db}",array('type'=>"sms_provider_key_with_param",'value'=>$sms_api_key_with_parameter),array('%s','%s'));
$wpdb->insert("{$db}",array('type'=>"sms_provider_sender_id_with_param",'value'=>$sms_api_sender_id_with_parameter),array('%s','%s'));
$wpdb->insert("{$db}",array('type'=>"sms_provider_custom_with_param",'value'=>$sms_custom_values_with_parameter),array('%s','%s'));
}