Bath queries in PHP

Discussion in 'MySQL' started by ignas2526, May 28, 2009.

  1. #1
    Hello,
    I searching for way to perform bath MySQL queries in PHP.
    I already know about loops, this however still same multiple queries, but with more load, because now its also loop.
    What i trying to find is pure way to make bath queries, then mysql_query being executed one time. I found what if you instead of ; use ;; like this:
    mysql_query("DELETE FROM table1 WHERE value='1';;
    DELETE FROM table2 WHERE value='2';;");
    PHP:
    MySQL will not return error, however query will not be executed.
    I don't need to view result, i just need to execute query.
    Any ideas?
     
    ignas2526, May 28, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    I think you mean BATCH queries, right? :D Can you give us an example of how you are trying to use the batch queries? It will put the DELETE sample into context. If you simply want to delete multiple rows from the table, you can use the following format: DELETE FROM table WHERE value IN ('1','2','3','4','5') or use a subquery for larger value sets.
     
    Social.Network, May 28, 2009 IP
  3. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i need to execute DELETE queries for 1-10 tables(depending on user selection):
    DELETE FROM table1 WHERE value1='x';
    DELETE FROM table2 WHERE value4='x';
    DELETE FROM table3 WHERE value8='x';
    and so on...
     
    ignas2526, May 29, 2009 IP
  4. Ralle

    Ralle Active Member

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    You need to tell more of what you need. Is this enough?
    
    $tables = array('table1','table2','tablewhateveryoulike');
    foreach($tables as $t) {
        mysql_query("DELETE FROM ".$table." WHERE value='1'");
    }
    PHP:
     
    Ralle, Jun 1, 2009 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    mwasif, Jun 4, 2009 IP
  6. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Create an empty table and setup a delete trigger on this table
    In the delete trigger create multiple delete statements for all your tables.
    Then perform your delete on the empty table, this will trigger a delete on all your other tables.
     
    chisara, Jun 5, 2009 IP