Json_encoded值未更新到数据库

时间:2016-11-04 16:44:25

标签: php mysql json wordpress

我正在创建代码,我正在更新一个表,其中json_encoded值返回此代码

global $wpdb;    
$table_name = $wpdb->prefix . 'ab_payments';
$test = '{"items":[{"ca_id":1,"appointment_date":"2016-11-04 08:00:00","service_name":"wordpress developer","service_price":"10.00","deposit":"100%","number_of_persons":"1","staff_name":"admin","extras":[]}],"coupon":{"code":"5off","discount":"50","deduction":"0.00"},"customer":"admin"}';

$wpdb->query($wpdb->prepare("UPDATE $table_name SET details='$test' WHERE id LIKE '$paymentid'"));  

但问题是它没有更新数据库值。如果用简单的文本替换值,它的工作正常但是测试json_encoded值没有更新,请帮忙。

谢谢

1 个答案:

答案 0 :(得分:0)

感谢@tadman的wordpress占位符,它需要更新json_encode代码,以便更新代码并开始工作。

$wpdb->query($wpdb->prepare("UPDATE $table_name SET details=%s WHERE id=%d",$serialized,$paymentid));