激活带有一些 PHP 验证的规则时,我收到一条 SQL 错误消息。该规则的目标是检查用户在过去 24 小时内是否投票超过 2 次。这是我使用的代码:
// Configure your settings:
$daily_limit = 2;
$content_type = 'node';
$day = strtotime(date('Y-m-d'))-1;
// Load the active user account
global $user;
// Drupal has a security feature called the Database Abstraction Layer.
// You have to build DB queries with variables that are defined in an array.
// Define the query string, where ":drupaluid" etc. are arbitrary placeholders
$query = 'SELECT * FROM votingapi_vote WHERE uid=:drupaluid AND content_type=:drupaltype AND timestamp > :day';
// Define each placeholder
$variables = array(':drupaluid' => $user->uid, ':drupaltype' => $content_type, ':day' => $day);
// Query the Drupal database
$result = db_query($query, $variables);
// Count the number of rows returned from the Drupal database
// From: http://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query/7
$nodecount = $result->rowCount();
// Set the flag as to whether this Rule is effective or not
if ( $nodecount >= $daily_limit) {
return TRUE; // You will be over the accepted quota
} else {
return FALSE; // Still got room. Allow the new node.
}
我试图调试查询,但即使是一个简单的查询$query = 'SELECT * FROM votingapi_vote WHERE uid = 1
也不能在 Php 中工作,而它在 mysql 控制台中工作。有人看到这个错误吗?