在一瞬间使用INSERT和SELECT时返回唯一ID

时间:2015-03-23 13:15:35

标签: php mysql model-view-controller pdo return

我正在使用mvc编写一个程序,因为我写的程序是为了接受银行交易,这个程序给我的复制对我来说非常重要。我需要这个没有任何逻辑错误的工作,一切都应该以需要的焦点锻炼,并给我我希望它给予的确切的东西。我希望它为我做的事情是,一些信息将通过Web服务(如价格,信息等)发送到程序,然后使用控制器检查信息并调用模块,并将信息发送给它。它将模块信息放入stdclass,然后使用PDO模块创建一个事务。当事务处于工作状态时,会为数据库发送一个insert命令,然后我们有一个SELECT命令,即使在insert命令之后程序运行良好,但是当SELECT工作时,我们有重复的ID,这是问题所在:

我的代码:

//WSDL Creattor And Class
<?php
ini_set("soap.wsdl_cache_enabled", 1);
set_time_limit(300);

class wsdl extends Controller
{
public function index()
{


  if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
        $servidorSoap = new SoapServer('http://' . $_SERVER['SERVER_NAME'] . '/wsdl');
        $servidorSoap->setClass('wsdl');
        $servidorSoap->handle();
                }
}

public function request($pin = null, $amount = 1, $callback = null, $orderid = null, $desc = null)
{
    if(empty($callback))
        return -10; // call back is empty.

    if (empty($pin) && $result->pin != $pin)
        return -1; // pin invalid


    $this->Model("payment");

   $au = $this->mod->Request($result, $amount, $callback, $orderid, $desc);

  return $au;


}
}

付款方式:

<?php
class Payment_mod extends Model
{
public function Request($gateway, $amount, $callback, $orderid,   $description)
{
// using pdo module
    $this->DB->CONNECT->beginTransaction();
    try {
        $trans = new stdClass;
        $trans->gateway_id = $gateway->id;
        $trans->au = str_replace('.', '_temp_', microtime(true)); 
        $trans->price = $amount;
        $trans->order_id = $orderid;
        $trans->ip = $_SERVER['REMOTE_ADDR'];
        $trans->time = time();
        $trans->call_back = $callback;
        $trans->description = $description;
        $this->DB->Insert("trans", $trans); // insert into table trans …
        $id = $this->DB->Fetch("trans", "`gateway_id` =" . $trans->gateway_id . " AND `price`=".$trans->price." AND time = " . $trans->time)->id; // select id from trans where …
        $u = new stdClass;
        $u->t_id = $id;
        $this->DB->Insert("test",$u); // insert into test . it for test table for check result
        $this->DB->CONNECT->commit();
    } catch (Exception $e) {
        $this->DB->CONNECT->rollBack();
                    return -9; // return unknow error.
    }
   return $id;
}
}

为了解问题究竟在哪里以及每个ID重复多少次,我添加了一个表,我获得了SELECT的返回数据量并将其放入数据库。当我按住f5键几秒钟时,它会显示每个ID重复近9次。

截图: http://uploads.im/biWEn.jpg 注意:此图片显示了ID的重复次数。

问题在哪里?我需要这个为每个电话重复一个特定的ID。 我在YII框架中做了确切的事情,我在那里没有任何问题,并且程序正如我需要的那样工作。如果你帮助我,我会很高兴。

0 个答案:

没有答案