MySQLi获取最后一个插入ID并传递true函数

时间:2015-05-31 18:01:15

标签: php mysqli mysql-insert-id

在我试图从查询中检索last_insert(ID)时,在这里调用函数是我调用函数的地方:

$lead = $_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];

我没有得到任何结果?这是我的addLead函数:

function addLead(array  $lead_data, $number, $user) {               

        //check if lead with same number and name exist in db
        if ($checker =  >= 1)
        {
            //return lead id as existed
            $data = $query->fetch_array(MYSQLI_ASSOC);      
            return array('id'=>$data['lead_id'], 'exists'=>true);           
        }
        else
        {
            //insert new lead into db
            if ($query = $this->QueryDB("INSERT", "INTO leads (lead_name)
                                               VALUES ('".$this->EscapeString($lead_data['lead_name'])))
              {
                  //return lead id as new
                  return array('id'=>$this->insert_id, 'exists'=>false);
              }
              else 
              {
                 //output error if insertion fail       
                  return false;
              }
}}

1 个答案:

答案 0 :(得分:0)

您正在从<title>函数返回数组,但在调用时您没有进入任何变量:

addLead

应如下所示:

$_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];