开发者

PHP & MySQL TRUNCATE TABLE returns false with AMFPHP

I have look开发者_开发问答ed at other topics, and I can't figure out whats wrong here. If I replace the TRUNCATE query with a simple SELECT * for example, I do get results. But this returns false. I copied the following code from this topic hoping to get a result: PHP & MySQL: Truncate multiple tables

And I am doing this through AMFPHP.

# the host used to access DB
define('DB_HOST', 'localhost');

# the username used to access DB
define('DB_USER', 'usr');

# the password for the username
define('DB_PASS', '***');

# the name of your databse
define('DB_NAME', 'name');

//$connection = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);


$connection = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);

if (mysqli_connect_errno())
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "TRUNCATE TABLE `books`";

$result = $connection->query($query);
if($result)
{
    return $result;
}
else
{
    return false;
}


Does the MySQL user have the required privalages to truncate the table? From the MySQL docs:

[TRUNCATE] requires the DROP privilege as of MySQL 5.1.16. (Before 5.1.16, it requires the DELETE privilege).

Edit: not having the privalage would generate an error of some kind - are you logging or are able to see any query errors?


According to the documentation, "Truncation operations do not return a meaningful value for the number of deleted rows. The usual result is “0 rows affected,” which should be interpreted as “no information.” See http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

So, it looks like your if statement will go down the else path even if the truncate is successful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜