2

用户发送 sql 查询,有时(通常是服务器繁忙)重复的 sql 行。我想阻止它。例如,如果用户同时发送相同的查询,则 sql 只接受一个查询。我不想总是删除它。我可以在 phpmyadmin 上做吗?

如果我不能,这个 php 中的问题: http ://www.speedyshare.com/S4QRj/Automation.php

我认为在这段代码中:

    private function returnunitsComplete() {
    global $database;
    $time = time();
    $q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = '0' and ".TB_PREFIX."movement.sort_type = '4' and endtime < $time";
    $dataarray = $database->query_return($q);


    foreach($dataarray as $data) {

    $tribe = $database->getUserField($database->getVillageField($data['to'],"owner"),"tribe",0);

    if($tribe == 1){ $u = ""; } elseif($tribe == 2){ $u = "1"; } elseif($tribe == 3){ $u = "2"; } elseif($tribe == 4){ $u = "3"; } else{ $u = "4"; }
    $database->modifyUnit(
            $data['to'],
            array($u."1",$u."2",$u."3",$u."4",$u."5",$u."6",$u."7",$u."8",$u."9",$tribe."0","hero"),
            array($data['t1'],$data['t2'],$data['t3'],$data['t4'],$data['t5'],$data['t6'],$data['t7'],$data['t8'],$data['t9'],$data['t10'],$data['t11']),
            array(1,1,1,1,1,1,1,1,1,1,1)
    );
    $database->setMovementProc($data['moveid']);
    }

有时返回单位和报告重复。对不起,我的英语不好。谢谢...

4

2 回答 2

2

CONSTRAINT在你的表中使用PRIMARY KEY和/或UNIQUE KEY。他们不会接受相同的价值。

例子

CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
PRIMARY KEY (P_Id)  //primary key
)

有关更多信息,请参阅此处

于 2012-12-29T11:42:09.173 回答
2

如果要确保列对col1col2tbl1不包含重复的值对(但每列本身可以),您可以创建必要的唯一索引

ALTER TABLE tbl1
  ADD UNIQUE KEY(col1, col2)

文档(MySQL):http ://dev.mysql.com/doc/refman/5.1/en/alter-table.html

于 2012-12-29T11:53:21.983 回答