code is below. Seems like when I run this file, it doesn't do anything.
header('Content-Type: application/json');
$DB = new mysqli("localhost", "root", "root", "friendslist");
if($DB->connect_errno) {
die("Connect failed: ". $DB->connect_error);
}
$DB->query("DELETE * FROM users");
$DB->query("ALTER TABLE users AUTO_INCREMENT = 1");
$DB->close();
echo json_encode(Array('status' => 'ok'));
Your query has incorrect syntax. If you read the documentation, you'll see that the valid syntaxes of DELETE
are either:
DELETE FROM users
or:
DELETE users.* FROM users
where .*
is optional in the second version. But DELETE *
is not valid.
You could also just use TRUNCATE tablename
to delete everything from the table and reset the auto increment ID in one step.
You should also check whether queries succeed:
$DB->query("DELETE * FROM users") or die ($DB->error);
would have told you that there was a syntax error. Then I'm sure you would have checked the documentation to see what the correct syntax is, and fixed it right away, rather than going the slow route of posting a question to SO.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments