从Wordpress端点插入后,MySQL触发器无法触发

时间:2018-04-23 17:41:00

标签: mysql

我想删除除前10名以外的所有高分。

我的查询在PHPMysql中作为查询工作正常,但是当我尝试在触发器中使用它时,它不会触发。

如果有人有任何建议或需要其他信息,请告知我们。感谢。

//The query
DELETE FROM ONEGameleaderboard WHERE _id Not IN
 (SELECT * FROM (SELECT _id FROM ONEGameleaderboard ORDER BY Score DESC , Date ASC LIMIT 10)  as t)

//The Trigger insert query
CREATE TRIGGER `ONEGameleaderboardTop10Limit` AFTER INSERT ON `ONEGameleaderboard`
 FOR EACH ROW DELETE FROM ONEGameleaderboard WHERE _id Not IN
 (SELECT * FROM (SELECT _id FROM ONEGameleaderboard ORDER BY Score DESC , Date ASC LIMIT 10)  as t)

//The insert code form the WordPress endpoint (Which inserts the data just fine)
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
 if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

   $parameters = $request->get_json_params();

 if($request['id'] == 1)
    {
    $sql = "INSERT INTO ONEGameleaderboard (Date, Name, Score) VALUES ('$parameters[Date]', '$parameters[Name]', '$parameters[Score]')";
  }
elseif($request['id'] == 2)
    {
  $sql = "INSERT INTO TWOGameleaderboard (Date, Name, Score) VALUES ('$parameters[Date]', '$parameters[Name]', '$parameters[Score]')";
  }
 elseif($request['id'] == 3)
    {
  $sql = "INSERT INTO THREEGameleaderboard (Date, Name, Score) VALUES ('$parameters[Date]', '$parameters[Name]', '$parameters[Score]')";
  }
  else
    {       
            $message = 'No Leaderboard Table for this Index';
            return new WP_ERROR('no_data', $message, array('status' => 404));
    }


 if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
} 

$conn->close();

0 个答案:

没有答案