亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP inserts data into the MySQL database in a loop. How to determine whether each item is inserted successfully?
阿神
阿神 2017-06-30 09:53:58
0
6
963

Just like the title.

            while(! feof($file)){
                $data= fgets($file);//fgets()函數(shù)從文件指針中讀取一行
                $res = $this->Model->function($data);//插入數(shù)據(jù)的方法
            }
            //比如這種的怎么判斷每一行都插入成功
阿神
阿神

閉關(guān)修行中......

reply all(6)
學習ing

//Define variable num
$num = 0;
while (! feof($file)) {

$data= fgets($file);//fgets()函數(shù)從文件指針中讀取一行
$res = $this->Procesratio->promction($data);

// 直接在這里判斷
if (!$res) {
    $num += 1;
}

}

// Judge the value of num here
if ($num == 0) {

// 全部成功

} else {

// $num即為失敗條數(shù)

}

劉奇

Start the transactiontransaction, and as long as there is an error, it will rollback and throw an exception

巴扎黑
if($res == true){
   echo "success";
}else{
    echo "fault";
}
巴扎黑
while(! feof($file)){
    $data= fgets($file);//fgets()函數(shù)從文件指針中讀取一行
    $res = $this->Model->function($data);//插入數(shù)據(jù)的方法
    if($res){
        echo "success!";
    }else{
        echo "error!。。。try again....";
        $this->Model->function($data)
    }
}

After the insertion is successful, data will be returned. Just make a judgment based on the return! !

小葫蘆

For this large amount of data insertion method, if the online business is not so busy, you can consider inserting in batches. After batch inserting, the returned result is the number of affected rows. The returned results are easier to search and the efficiency will be higher than this. Or business, simple violence.

黃舟

It is recommended to use things, so that you can at least ensure the consistency of the data.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template