Reputation: 63
I'm trying to truncate the table named 'comments' Yet every time I run the script nothing happens. What is wrong with my syntax?
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
mysql_select_db("dbname", $con);
mysql_query("TRUNCATE TABLE 'comments'");
mysql_close($con);
?>
Upvotes: 0
Views: 5719
Reputation: 47034
The quotes, try changing it to:
$result = mysql_query("TRUNCATE TABLE `comments`");
if ( !$result ) print(mysql_error());
This will also tell you what goes wrong.
Upvotes: 2
Reputation: 109
you seem to select the database "dbname" only if the connection to the mysql server failed ( $con == FALSE ).
you probably need to change your if condition to:
if ( $con )
mysql_select_db("dbname", $con);
Upvotes: 2