我试图让最后一个插入id MySQL,但它不会返回任何内容。行已插入数据库中,$ wpdb-> last_query也会提供最后插入的查询。 这是我的代码
global $wpdb;
$table_name = $wpdb->prefix . "request_from";
$wpdb->insert($table_name,
array('pre' => $prefix,
'first_name' => $first_name,
'middle_name' => $middle_initial,
'last_name' => $last_name,
'badge_name' => $name_badge,
'title' => $title,
'company' => $company,
'direct_mail' => $direct_mail,
'twitter' => $twitter_handle,
'direct_phone' => $direct_phone,
'address' => $address,
'address2' => $address_2,
'city' => $city,
'state' => $state,
'province' => $province,
'zip' => $zip_code,
'country' => $country,
'cc' => $cc,
'cc_contact' => $second_contact,
'cc_mail' => $second_email,
'cc_phone' => $second_phone)
);
$x= $wpdb->last_query;
$id = $wpdb->insert_id
我有一个名为id且具有自动增量值
的列id int(11) No None AUTO_INCREMENT
答案 0 :(得分:0)
按照Codex中的wpdb参考进行故障排除:
请通过打印或转储变量检查代码,
global $wpdb;
$table_name = $wpdb->prefix . "request_from";
$wpdb->insert($table_name,
array('pre' => $prefix,
'first_name' => $first_name,
'middle_name' => $middle_initial,
'last_name' => $last_name,
'badge_name' => $name_badge,
'title' => $title,
'company' => $company,
'direct_mail' => $direct_mail,
'twitter' => $twitter_handle,
'direct_phone' => $direct_phone,
'address' => $address,
'address2' => $address_2,
'city' => $city,
'state' => $state,
'province' => $province,
'zip' => $zip_code,
'country' => $country,
'cc' => $cc,
'cc_contact' => $second_contact,
'cc_mail' => $second_email,
'cc_phone' => $second_phone)
);
$x= $wpdb->last_query;
$id = $wpdb->insert_id;
// Let's output the last autogenerated ID.
echo $wpdb->insert_id;
// This returns the same result
echo mysql_insert_id();