user1206214
user1206214

Reputation: 63

Using truncate tables, no result

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

Answers (2)

mvds
mvds

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

sotn0r
sotn0r

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

Related Questions