Prepared statements while fetching prepared statement

送分小仙女□ 提交于 2020-01-06 07:55:31

问题


I want to make a loop with one INSERT query for each fetched row from a previous query with prepared statements. In a more visual way:

MAKE QUERY
  While Fetching
    - Make new query

I can't close my statement since I need it to keep working... The problem is that when we use prepared statements, we have to fetch all data before doing a new prepare(). So, how could I do this? Maybe without statements, but it's not a nice solution.


回答1:


You are going to kill your DB (and if you have a DBA your DBA is going to kill you) if you try to do this. The problem is that what you want to do is send one inser request per line to the database. You have to create and dispose of all these commands over and over again for each line of data. That is expensive.

If you are hard-set on doing it, Nothing prevents you from creating a second prepared statement (with a different name of course) within a loop which reads from the first, but I highly advise against it. At the very least, buffer your incoming data and insert a few hundred rows at a time.



来源:https://stackoverflow.com/questions/13103085/prepared-statements-while-fetching-prepared-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!