php - Delete row by row or a bulk -


i like delete bulk of data. table have approximately 11207333 now

however have several method delete it.

the data deleted approximately 300k. have 2 method unsure 1 perform faster.

my first option:

$start_date     = "2011-05-01 00:00:00"; $end_date       = "2011-05-31 23:59:59"; $sql = "delete table date>='$start_date' , date <='$end_date'"; $mysqli->query($sql); printf("affected rows (delete): %d\n", $mysqli->affected_rows); 

second option:

$query = "select count(*) count table date>='$start_date' , date <='$end_date'"; $result = $mysqli->query($query); $row = $result->fetch_array(mysqli_assoc); $total = $row['count'];  if ($total > 0) {     $query = "select * table date>='$start_date' , date <='$end_date' limit 0,$total";     $result = $mysqli->query($query);       while ($row = $result->fetch_array(mysqli_assoc)) {             $table_id = $row['table_id']; // primary key             $query = "delete table table_id = $table_id limit 0,$total";             $mysqli->query($query);      } } 

this table data displayed client see, afraid if deletion go wrong , affect client.

i wondering there method better mine.

if guys need more info me let me know.

thank you

in opinion, first option faster.

the second option contains looping think slower because keeps looping several times looking table id.

if did not provide wrong start , end date, think you're safe either option, option 1 faster in opinion.

and yea, dont see deletion in option 2, assume have in mind using looping method.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -