Need help with my truncate table function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Need help with my truncate table function

Post 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.
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Re: Need help with my truncate table function

Post by funkyapache »

Not to wrong I sorted it out I used mysql_error() instead of mysql_fetch_array.
Post Reply