1

我在尝试从请求表中截断“requestID”字段时遇到问题。

这是我的代码。

<?php
        include 'mysql_connect.php';
     USE fypmysqldb;
     TRUNCATE TABLE requestID;
     echo "Request ID table has been truncated";     
?>

我正在使用服务器端脚本,所以不知道会出现什么错误。

有人有想法吗?

4

2 回答 2

1

您没有执行查询,您只是将 SQL 代码放入无效的 PHP 中。这假设您使用的是mysql_*()api(在查看您之前的一个问题后我有点怀疑),但如果您使用的是 MySQLi 或 PDO,则可以进行调整。

 // Assuming a successful connection was made in this inclusion:
 include 'mysql_connect.php';
 // Select the database
 mysql_select_db('fypmysqldb');
 // Execute the query.
 $result = mysql_query('TRUNCATE TABLE requestID');

 if ($result) {
   echo "Request ID table has been truncated";  
 }
 else echo "Something went wrong: " . mysql_error();
于 2012-04-24T01:41:37.063 回答
0

mysql_query查看执行查询执行的函数。执行查询的代码应如下所示。

$link = mysql_connect('host', 'username', 'password') or die(mysql_error());
mysql_select_db("fypmysqldb", $link) or die(mysql_error());
mysql_query("TRUNCATE TABLE requestID", $link) or die(mysql_error());
mysql_close($link);
于 2012-04-24T01:41:42.880 回答