簡體   English   中英

無法使用CodeIgniter更新數據庫

[英]Can't update database using CodeIgniter

我目前正在使用Codeigniter。 我正在嘗試通過這種方式更新數據庫:

function index($email) //function wchich will reset the password in the database;
{
    $new_password = random_string('alnum', 16); //generate random password
    $this-> db->set('password', md5($new_password), FALSE);
    $this-> db->where('email', $email);
    $this-> db->update('CI_TEST');

    echo ''. $this->db->last_query();
    exit();
    echo '-> '. $this->db->affected_rows(). '</br>';
    $query = $this->db->get();
    return ($new_password);
}

我在Codeigniter網站上了解了如何更新數據庫。 否則,我的瀏覽器不會向我拋出任何錯誤,但是我嘗試使用以下適當的函數來顯示最后一個查詢,它准確地給出了我想做的事情:

更新ci_test SET密碼= 5167ec0e9c076c2c45550ee7581c07f6 WHERE email ='test@gmail.com'

但是,當我使用$ this-> db-> affected_row()函數知道數據庫是否成功修改時,它只是給我

-1

我在數據庫中進行了驗證,沒有任何更新。 有誰能告訴我會發生什么? 謝謝 :)

嘗試這個

function index($email)
{
    $new_password = random_string('alnum', 16);

    $data = array(
        'password' => $new_password
    );

    $this->db->where('email', $email);
    $this->db->update('CI_TEST', $data);

    $count = $this->db->affected_rows();
    if($count==1)
    {
        return $new_password; 
    }
    else
    {
        echo 'too many affected rows here';
    }        
}

$this->db->update(); 在Codeigniter中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM