mysqli truncate

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

mysqli truncate

Postby 12strings » 27. September 2014 20:19

I need to remove all records in a table and set the id to 1. can't figure out how? Thanks in advance.
After 5 minutes, no action, no error message, no chg to table.
I'm running PHP version 5.4.4

Code: Select all
<?php
$db = new mysqli("localhost","root","cookie","homedb");
if($db->query("ALTER TABLE calculator AUTO_INCREMENT = 1") == false) {
$db->rollback();
  throw new Exception("autoincrement reset failed: ".$db->error);
 }
$db->commit();
?> 
12strings
 
Posts: 31
Joined: 04. April 2013 17:56
Operating System: win 7 32 bit

Re: mysqli truncate

Postby Nobbie » 27. September 2014 21:30

Simple run a "Drop Table" and create a new table after. Truncate does not reset the primary key.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 9 guests