Performance in PDO / PHP / MySQL: transaction versus direct execution

前端 未结 3 391
臣服心动
臣服心动 2020-12-20 23:39

I am looping through a number of values (1 to 100 for example) and executing a prepared statement inside the loop.

Is there and advantage to using a transaction - co

3条回答
  •  独厮守ぢ
    2020-12-21 00:06

    For a faster time you could do all the inserts in one shot, or group them together, perhaps 5 or 10 at a time, as if one insert fails the entire batch will.

    http://www.desilva.biz/mysql/insert.html

    A transaction will slow you down, so if you don't need it then don't use it.

    A prepared statement would be a good choice though even if you did batch inserts, as you don't have to keep building up the query each time.

提交回复
热议问题