2017-04-27 109 views
-1

我使用mysqli_multi_query執行多個查詢。我嘗試了很多東西,但找不到最後插入的ID。查找上次插入的ID,同時執行多個查詢

$fetchbasic = mysqli_fetch_array($resCheckres); 
$cpyname = $fetchbasic['name'].'(copy)'; 

$query1 = "CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM name_webinfo WHERE resume_id = ".$resume_id."; 
    UPDATE tmptable_1 SET resume_id = NULL , name = '".$cpyname."'; 
    INSERT INTO name_webinfo SELECT * FROM tmptable_1; 
    DROP TEMPORARY TABLE IF EXISTS tmptable_1;"; 

$resCheckres = mysqli_multi_query($link,$query1); 

我需要最後插入的ID此查詢:INSERT INTO name_webinfo SELECT * FROM tmptable_1;

+0

請問您能否清楚解釋您的問題 –

+0

i需要lastinsertid這個查詢「INSERT INTO name_webinfo SELECT * FROM tmptable_1;」 – patel

+0

'從tmptable_1'選擇MAX(ID)如果是工作,請使用這個bro請告訴我 –

回答

0

下面的代碼爲我工作它給你的ID array

do { 
    $ids[] = $link->insert_id; 
    $link->next_result(); 
} while($link->more_results()); 
print_r(ids); 
0

試試這個(把選擇LAST_INSERT_ID插入語句):

$fetchbasic = mysqli_fetch_array($resCheckres); 
$cpyname = $fetchbasic['name'].'(copy)'; 

    $query1 = "CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM name_webinfo WHERE resume_id = ".$resume_id."; 
     UPDATE tmptable_1 SET resume_id = NULL , name = '".$cpyname."'; 
     INSERT INTO name_webinfo SELECT * FROM tmptable_1; 
     SELECT LAST_INSERT_ID(); 
     DROP TEMPORARY TABLE IF EXISTS tmptable_1;"; 


    $resCheckres = mysqli_multi_query($link,$query1); 
    do { 
     if ($result = $link->store_result()) { 
      while ($row = $result->fetch_row()) { 
      echo ($row); 
      } 
     } 
    } while ($link->next_result());