Loren Zimmer
Loren Zimmer

Reputation: 480

Php code to delete all records...should it be working

Should this delete all records in my SQL table?

<?php
$con = mysql_connect("localhost","bikemap","pedalhard");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

mysql_query("DELETE * FROM gpsdata");

mysql_close($con);
?>

Upvotes: 5

Views: 4451

Answers (3)

Laith Shadeed
Laith Shadeed

Reputation: 4321

DELETE differs from Truncate. But if your use case is simple, go to any one.

Truncate

  • DDL command
  • You can't rollback
  • Table Structure will be re-created.
  • Your indexes will be lost.
  • Will delete all rows.

DELETE

  • DML command
  • You can rollback.
  • Structure remains as it is.
  • You can specify a range of rows to delete.

Upvotes: 1

ford
ford

Reputation: 1887

You might want to check out MySQL's Truncate command. That should remove all records easily.

Upvotes: 2

Mark Byers
Mark Byers

Reputation: 839054

The DELETE syntax doesn't allow a star between DELETE and FROM. Try this instead:

mysql_query("DELETE FROM gpsdata");

Upvotes: 5

Related Questions