Page 1 of 1

Need help with my truncate table function

Posted: Tue Apr 07, 2009 2:25 pm
by funkyapache
Hi,

I have the following bit of PHP. I'm trying to truncate a table called tbl_demo in my demo db.

Code: Select all

<?php
//This will be used to drop and create the image table
//and reload the images into the table
  echo "Truncating Demo table...";
  $query = "TRUNCATE TABLE ".DB_NAME . ".tbl_demo";
  $result = mysql_query ($query, $connection);
  confirm_query($result);
  if(mysql_fetch_array($result)){
    echo "Table Truncated";
  }
?>
This is my confirm query function which is in another file that I include.

Code: Select all

function confirm_query($result_set) {
        if (!$result_set) {
            die("Database query failed: " . mysql_error());
        }
    }
I keep getting this error message
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource


How can I truncate my table and check that it was successful. I am new to php so really appreciate your help.

Re: Need help with my truncate table function

Posted: Tue Apr 07, 2009 2:52 pm
by funkyapache
Not to wrong I sorted it out I used mysql_error() instead of mysql_fetch_array.