• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

MySQL query in PHP with two SQL statements?

I have the following $sql statement in a PHP script:
is it possible to include a Truncate command on a tables TABLE1,TABLE2 within this bit of code prior to running the INSERT statement?  I basically need to empty some tables before I INSERT.  How do I best do this?

$sql = "INSERT INTO simages (sImage_Name) VALUES ('".$record[$primary_key]."_".$record[$mls_key]."')";

Open in new window

0
pda4me
Asked:
pda4me
  • 2
  • 2
  • 2
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I would rather run the statments apart ... why do you want to run this on a "single" $sql?
0
 
Dave BaldwinFixer of ProblemsCommented:
The PHP/MySQL driver won't allow you to combine queries into one single statement.
0
 
pda4meAuthor Commented:
I am not 100% where to call the new query...I am a newbie with this:

Ideally I would like to create a new function at the very top to empty the tables before the rest of the script runs, can you show me how to do that?

function setupRecord($resource,$record,$mls_key) {
      global $primary_key;
      global $photos_process;
      global $conn;
      
      
      if (checkDuplicates($resource,$record[$primary_key]))
          $ret = updateRecord($resource,$record);
      else {
          $ret = insertRecord($resource,$record);
            $sql = "INSERT INTO simages (sImage_Name) VALUES ('".$record[$primary_key]."_".$record[$mls_key]."')";
          
            
            h_query($sql, $conn);             

    }      
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Dave BaldwinFixer of ProblemsCommented:
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I wonder why you want to truncate (delete) 2 tables just before you insert 1 record.

function setupRecord($resource,$record,$mls_key) {
      global $primary_key;
      global $photos_process;
      global $conn;
      
      
      if (checkDuplicates($resource,$record[$primary_key]))
          $ret = updateRecord($resource,$record);
      else {
          $ret = insertRecord($resource,$record);

            $sql = "truncate table table1";
            h_query($sql, $conn);             

            $sql = "truncate table table2";
            h_query($sql, $conn);             

            $sql = "INSERT INTO simages (sImage_Name) VALUES ('".$record[$primary_key]."_".$record[$mls_key]."')";
            h_query($sql, $conn);             

    }      
}

Open in new window

0
 
pda4meAuthor Commented:
Perfect, thanks for the help guys!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now