title: PHP & MySQL: Truncate multiple tables
body: <p>I tried to truncate a table but why is it not working? must something wrong in the database query?</p>
  
  <pre><code>$sql = "TRUNCATE TABLE `table_name`";
  
  $result = $connection -&gt; query($sql);
  </code></pre>
  
  <p>Ideally, I want to truncate all tables in one go - is it possible?</p>
  
  <p>if you wonder what is inside the class that I use to make the database queries, here is it,</p>
  
  <pre><code>#connects the database and handling the result
  class __database {
  
   protected $connection = null;
   protected $error = null;
  
   #make a connection
   public function __construct($hostname,$username,$password,$database)
   {
    $this -&gt; connection = new mysqli($hostname,$username,$password,$database);
  
    if (mysqli_connect_errno()) 
    {
     printf("Connect failed: %s\n", mysqli_connect_error());
     exit();
    }
   }
  
   ...
  
   #performs a query on the database
   public function query($query)
   {
    $result = $this -&gt; connection -&gt; query($query); 
    if($result) 
    {
     return $result;
    } 
    else
    {
     $this -&gt; error = $this -&gt; connection -&gt; error;
     return false;
    }
  
   }
  
  
   #display error
   public function get_error() 
   {
    return $this -&gt; error;
   }
  
   #closes the database connection when object is destroyed.
      public function __destruct()
      {
          $this -&gt; connection -&gt; close();
      }
  }
  </code></pre>
  
  <p>thanks.</p>
  
  <p><strong>edit:</strong></p>
  
  <p>below is how I call the db object,</p>
  
  <pre><code># the host used to access DB
  define('DB_HOST', 'localhost');
  
  # the username used to access DB
  define('DB_USER', 'root');
  
  # the password for the username
  define('DB_PASS', 'xxx');
  
  # the name of your databse 
  define('DB_NAME', 'xxx'); 
  
  $connection = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
  </code></pre>