这是我的代码:尝试插入JSON字符串WPDB与
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.openweathermap.org/data/2.5/weather?q=".$location.",de&lang=de&APPID=abc");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch); //JSON string
curl_close($ch);
//json_decode($output);
//serialize($output);
$table_name = $wpdb->prefix . 'dmd_weather';
$wpdb->insert(
$table_name,
array(
'time' => current_time('mysql'),
'type' => 'wetter',
'key' => $location, //<- normal string
'value' => $output //<- json string
)
);
我不能插入上面我的查询数据。
如果我更改变种$output
,如$output = 1
,它的工作原理是完美的。但不是用json字符串。
有没有把json字符串插入数据库与wordpress的技巧?
感谢您的回答。但它不起作用。 – cgee