尝试使用wordpress wpdb 运行sql查询
global $wpdb;
$sql = $wpdb->prepare("INSERT INTO $wpdb->wp_advert_management(`category_id`,`sub_category_id`,`third_level_sub_category_id`,`fourth_level_sub_category_id`,`model_year`, `car_name`, `registration`, `milage`, `fuel_type_id`, `transmision_type_id`, `price`, `location`, `description`, `created_date`, `modified_date`, `created_by`, `created_ip`, `modified_ip`, `user_id`, `is_active`, `phonenumber`)
VALUES ('".$category_id."','".$sub_category_id."','".$third_level_sub_category_id."','".$fourth_level_sub_category_id."','".$model_year."','".$car_name."','".$registration."','".$milage."',
'".$fuel_type_id."','".$transmision_type_id."','".$price."','".$location."',
'".$description."','".$date."','".$modified_date."','".$created_by."','".$created_ip."','','".$user_id."','".$is_active."','".$phonenumber."')");
$wpdb->query($sql);
它返回的错误是调用成员函数prepare(),似乎是PDO错误?
我必须在wordpress中包括额外的文件吗?从查询的文档来看,看起来是正确的
或者我应该在没有准备的情况下直接使用wpdb->insert?
抱歉完全错误
调用非对象上的成员函数prepare()
尝试过这个
global $wpdb;
$wpdb->insert("wp_advert_management", array(
"category_id" => $category_id,
));
相同错误在非对象上调用成员函数prepare()
有人能解释这个错误吗?所以我可以考虑修复
尝试以下代码
global $wpdb;
$sql = $wpdb->prepare("INSERT INTO ".$wpdb->wp_advert_management." (`category_id`,`sub_category_id`,`third_level_sub_category_id`,`fourth_level_sub_category_id`,`model_year`, `car_name`, `registration`, `milage`, `fuel_type_id`, `transmision_type_id`, `price`, `location`, `description`, `created_date`, `modified_date`, `created_by`, `created_ip`, `modified_ip`, `user_id`, `is_active`, `phonenumber`)
VALUES ('".$category_id."','".$sub_category_id."','".$third_level_sub_category_id."','".$fourth_level_sub_category_id."','".$model_year."','".$car_name."','".$registration."','".$milage."',
'".$fuel_type_id."','".$transmision_type_id."','".$price."','".$location."',
'".$description."','".$date."','".$modified_date."','".$created_by."','".$created_ip."','','".$user_id."','".$is_active."','".$phonenumber."')");
$wpdb->query($sql);