send multiple queries to mysql

Discussion in 'Databases' started by blogreview, Nov 26, 2012.

  1. #1
    Hello,

    i use a client server application; so many times i would have to call several update statements in a single save button click. now i call execute for each update query from my client app. my question: is it possible to put the queries into a single string and pass it to mysql and execute it at once . i think it is a very common scenarion .

    Thanks. Any help would be appreciated
     
    blogreview, Nov 26, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    That depends on your data. If the user isn't changing anything (he just clicks the button once) you should be able to write a single update statement with a WHERE clause.

    If you're updating multiple tables, do that on the server if all the data from the client is the same for every one you're now generating.

    If you REALLY need to cut down on database server bandwidth usage, try a stored procedure.
     
    Rukbat, Nov 27, 2012 IP
  3. concerto49

    concerto49 Greenhorn

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    10
    #3
    You should be able to do this with prepared statements etc and batch it. You'd need to make sure any SQL injection issues are dealt with though.
     
    concerto49, Dec 5, 2012 IP