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

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

兩個(gè)mysqli查詢

兩個(gè)mysqli查詢

PHP
蝴蝶不菲 2019-07-22 10:06:19
兩個(gè)mysqli查詢有可能有像這樣的兩個(gè)mysqli_查詢嗎?mysqli_query($dblink, "INSERT INTO images (project_id, user_id, image_name, date_created, link_to_file, link_to_thumbnail, given_name) VALUES ('$project_id', '$user_id', '$image_name', '$date_created', '$link_to_file', '$thumbnail', '$ImageName')") or die(mysql_error());                           mysqli_query($dblink, "INSERT INTO images_history (project_id, user_id, image_name, date_created, link_to_file, link_to_thumbnail, given_name, day, month, year) VALUES ('$project_id', '$user_id', '$image_name', '$date_created', '$link_to_file', '$thumbnail', '$ImageName', '$day', '$month', '$year')") or die(mysql_error());基本上,我想更新DB中的兩個(gè)表。有更好的方法嗎?
查看完整描述

2 回答

?
慕的地8271018

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

一勞永逸!使用此函數(shù)可以獲得腳本中任意位置的無限數(shù)量查詢的結(jié)果。

職能:

您只需將多個(gè)查詢的輸出傳遞給函數(shù),它就會(huì)返回在每個(gè)查詢中找到的所有結(jié)果和錯(cuò)誤。

  function loop_multi($result){
    //use the global variable $conn in this function
    global $conn;
    //an array to store results and return at the end
    $returned = array("result"=>array(),"error"=>array());
    //if first query doesn't return errors
      if ($result){
        //store results of first query in the $returned array
        $returned["result"][0] = mysqli_store_result($conn);
        //set a variable to loop and assign following results to the $returned array properly
        $count = 0;
        // start doing and keep trying until the while condition below is not met
        do {
            //increase the loop count by one
            $count++;
            //go to the next result
            mysqli_next_result($conn);
            //get mysqli stored result for this query
            $result = mysqli_store_result($conn);
            //if this query in the loop doesn't return errors
            if($result){
              //store results of this query in the $returned array
              $returned["result"][$count] = $result;
            //if this query in the loop returns errors
            }else{
              //store errors of this query in the $returned array
              $returned["error"][$count] = mysqli_error($conn);
            }
        }
        // stop if this is false
        while (mysqli_more_results($conn));
      }else{
        //if first query returns errors
        $returned["error"][0] = mysqli_error($conn);
      }
    //return the $returned array
    return $returned;
  }

用法:

$query  = "INSERT INTO table1 (attribute1) VALUES ('value1');";$query .= "INSERT INTO table2 (attribute2) VALUES ('value2');";$query .= "SELECT * FROM table3;";//execute query$result = mysqli_multi_query($conn, $query);//pass $result to the loop_multi function$output = loop_multi($result);

輸出量

$Output包括由查詢排序的兩個(gè)數(shù)組“結(jié)果”和“錯(cuò)誤”。例如,如果您需要檢查在執(zhí)行第三個(gè)查詢并獲取其結(jié)果時(shí)是否發(fā)生了任何錯(cuò)誤,您可以這樣做:

if(isset($output['error'][2]) && $output['error'][2] !== ""){
  echo $output['error'][2];}else{
  while($row = $output['result'][2]->fetch_assoc()) {
    print_r($row);
  }}


查看完整回答
反對(duì) 回復(fù) 2019-07-22
  • 2 回答
  • 0 關(guān)注
  • 409 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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