【发布时间】:2015-06-12 12:59:13
【问题描述】:
开始交易的更好方法是什么? 内部过程还是 PHP 函数?
例如我这样调用 MySQL 程序:
function sendLeaguesToDb(){
$leagues = "";
try{
$this->PDO->beginTransaction();
$stmt = $this->PDO->prepare("call insupd_Leagues(:id,:name,:country,:sport_id,:his_data,:fixtures,:livescore,
:numofmatches,:latestmatch)");
$leagues=$this->soccer->GetAllLeagues();
foreach($leagues as $key=>$value){
$stmt->bindParam(':id',$value->Id);
$stmt->bindParam(':name',$value->Name);
$stmt->bindParam(':country',$value->Country);
$stmt->bindParam(':sport_id',$value->Sport_Id);
$stmt->bindParam(':his_data',$value->Historical_Data);
$stmt->bindParam(':fixtures',$value->Fixtures);
$stmt->bindParam(':livescore',$value->Livescore);
$stmt->bindParam(':numofmatches',$value->NumberOfMatches);
$stmt->bindParam(':latestmatch',$value->LatestMatch);
$stmt->execute();
$this->PDO->commit();
}
}
catch(XMLSoccerException $e){
echo "XMLSoccerException: ".$e->getMessage();
}
catch(PDOException $e){
echo "PDOException: ".$e->getMessage();
$this->PDO->rollback();
}
}
如果我想每分钟/小时尽可能快地发送/获取数据,这是一种好方法吗?
【问题讨论】:
-
这是您可以轻松地对自己进行基准测试的东西。
-
你到底是什么意思?
-
@user1814358:您可以执行两个包含该代码的不同文件,例如运行代码 10000 次,然后您只需计算哪个运行时间更长,您就会得到答案。
标签: php mysql pdo transactions