SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql query, different lines

    okay, this is a silly question, but if I wanted to create a query:
    Code:
    $sql="TRUNCATE table1";
    mysql_query($sql) or die('Could not wipeout: '.mysql_error());
    but make it so that $sql ends up producing two lines of query

    such that it would be the equivalent to the following text file sql:

    TRUNCATE table1;
    TRUNCATE table2;

  2. #2
    SitePoint Member csull's Avatar
    Join Date
    May 2003
    Location
    Atlanta, GA
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about:
    PHP Code:
    <?php
    $tables 
    = array('table1''table2');

    foreach (
    $tables as $table) {
      
    $sql "TRUNCATE " $table;
      
    mysql_query($sql) or die('Could not wipeout: '.mysql_error());
    }
    ?>

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can only execute one query at a time. If you have a file as the one shown above, something like this might work:

    PHP Code:
    $queries file('filename.sql');

    for( 
    $i 0$i sizeof($queries); $i++ )
      
    mysql_query($queries[$i]) or die(mysql_error()); 
    Is this what you're looking for? If not, let me know what it is that I've misunderstood.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was just wondering if there were a way for $sql to equal two lines of query, but I guess it can't happen... but it's okay

    maybe I'll do this:

    PHP Code:
    $tables = array('TRUNCATE table1''TRUNCATE table2');

    for( 
    $i 0$i count($tables); $i++ )
      
    mysql_query($tables[$i]) or die(mysql_error()); 
    thanks for your help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •