推 dream1x :謝謝您詳細解說 08/13 11:15
※ 引述《dream1x (翻桌客 )》之銘言:
: 目前程式碼
: mysql_query("delete from tra where tourId = 10", $link)or die(mysql_error());
: mysql_query("delete from bad where tourId = 10", $link)or die(mysql_error());
: mysql_query("delete from gue where tourId = 10", $link)or die(mysql_error());
: mysql_query("delete from rec where tourId = 10", $link)or die(mysql_error());
: mysql_query("delete from alb where tourId = 10", $link)or die(mysql_error());
: 感謝
在MYSQL 裡面,的確是有一種東西 叫做 delete multi
在我所有寫過的專案中,我沒有用過他XD
delete tra,bad,gue,rec,alb from tra,bad,gue,rec,alb
where tra.tourId =10 or bad.tourId =10 or gue.tourId =10 or
rec.tourId =10 or alb.tourId =10;
注意前後兩個都是tablename
相信我,你絕對不會覺得比較快的
倒不如改一下程式寫法
$tablename='tra,bad,gue,rec,alb';
foreach(explode(',',$tablename) as $v){
mysql_query("delete from $v where tourId = 10", $link)or die('');
}
應該比你原本的在寫作上快一些些吧?
補充說明:
mysql_query,不支援多行SQL指令。
http://tw.php.net/mysql-query
但對於PHP5以上,使用mysqli的,有個mysqli_multi_query,可以執行多行SQL指令
但我想對於MYSQL而言,效能應該是一樣的,一次輸入跟分開多次輸入
http://tw.php.net/mysqli.multi-query
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.186.42
※ 編輯: arrack 來自: 219.84.186.42 (08/13 02:52)