第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

WordPress 從數(shù)據(jù)庫(kù)中獲取最后一個(gè)插入 id

WordPress 從數(shù)據(jù)庫(kù)中獲取最后一個(gè)插入 id

PHP
Qyouu 2022-07-16 16:38:18
我想從數(shù)據(jù)庫(kù)中獲取最后插入的 id 我嘗試了很多代碼都無(wú)法獲取最后插入 id。我在下面給出了我的代碼。請(qǐng)任何人幫助并拯救我。            $users_table = $wpdb->prefix."users";            $saveFieldArray=array('user_login'=>'$utilisateurCand',                                'user_pass'=>'$passeCand',                                'user_email'=>'$emailCand',                                 user_registered=>CURRENT_TIMESTAMP());        $wpdb->insert( $users_table, $saveFieldArray);        echo $wpdb->last_query;                 echo $lastInsertId = $wpdb->insert_id; 
查看完整描述

3 回答

?
呼啦一陣風(fēng)

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊

基本上 - 如果您使用 WP 自己的功能,那么您將獲得成功的 ID


像這樣。


$userdata = array(

    'user_login' =>  $utilisateurCand,

    'user_pass'  =>  $passeCand,

    'user_email' =>  $emailCand,

);


$user_id = wp_insert_user( $userdata ) ;


// On success.

if ( ! is_wp_error( $user_id ) ) {

    echo "User created : ". $user_id;

}


查看完整回答
反對(duì) 回復(fù) 2022-07-16
?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

我已經(jīng)在我的項(xiàng)目中嘗試了下面的代碼來(lái)獲取 wordpress 中最后插入的 ID,我將我的代碼粘貼在下面,希望它對(duì)你有所幫助。


// While use wp_insert_post() use the below code

$post_ID = wp_insert_post($post);

print_r($post_ID);

如果帖子成功添加到數(shù)據(jù)庫(kù),則返回帖子的 ID。失敗時(shí),如果 $wp_error 設(shè)置為 false,則返回 0;如果 $wp_error 設(shè)置為 true,則返回 WP_Error 對(duì)象。


當(dāng)您使用 $wpdb->insert()函數(shù)將數(shù)據(jù)存儲(chǔ)在表中時(shí),您可以使用以下代碼。


$wpdb->insert()

$lastid = $wpdb->insert_id;

我希望這會(huì)對(duì)你有所幫助。


查看完整回答
反對(duì) 回復(fù) 2022-07-16
?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

$user_id = wp_insert_user(

array(

    'user_email'  =>  $emailCand,

    'user_pass' => $passeCand,

    'user_login' => $utilisateurCand,

    'role' => 'customer'

    )

);

if ( ! is_wp_error($user_id) ){

    wp_set_current_user( $user_id, $emailCand );

    wp_set_auth_cookie( $user_id, true, false );

    wp_redirect( home_url() );

}

測(cè)試和工作。


查看完整回答
反對(duì) 回復(fù) 2022-07-16
  • 3 回答
  • 0 關(guān)注
  • 117 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)