Php cron锁表每5分钟一次
每运行5,10,603600分钟cron, 当我检查errorlog时,我看到很多死锁异常,几乎每5分钟cron都会向日志发送死锁、超时和序列化错误 若我知道当两个或多个查询使用同一个表时会发生良好的死锁,那个么在我的代码中很有可能发生什么 我在每个cron中使用表映射2次,因为我需要映射每个团队 例如: 切尔西回归切尔西后 映射后的Everton返回Everton FC 我从大型xml文件中获取团队,当我杀死所有进程时,cron5可以在2分钟内运行,但当其他进程打开时,它需要一段时间 当我通过Php cron锁表每5分钟一次,php,mysql,transactions,deadlock,Php,Mysql,Transactions,Deadlock,每运行5,10,603600分钟cron, 当我检查errorlog时,我看到很多死锁异常,几乎每5分钟cron都会向日志发送死锁、超时和序列化错误 若我知道当两个或多个查询使用同一个表时会发生良好的死锁,那个么在我的代码中很有可能发生什么 我在每个cron中使用表映射2次,因为我需要映射每个团队 例如: 切尔西回归切尔西后 映射后的Everton返回Everton FC 我从大型xml文件中获取团队,当我杀死所有进程时,cron5可以在2分钟内运行,但当其他进程打开时,它需要一段时间 当我通过
检查时,显示打开的表,其中使用>0
图中的表大多使用2,有时使用1
function getMap($country,$data){
//echo $data . '<br>';
$fdata = $data;
$query = $this->PDO->prepare("CALL GetMap(:data)");
$query->bindParam(':data', $fdata);
$query->execute();
//echo 'DATA: ' . $data. ' RES: '.$res . '<br>';
$res = $query->fetchColumn();
if($res!=''){
$query->closeCursor();
$sql = "UPDATE map SET Country = :country WHERE Base = :base";
$q2 = $this->PDO->prepare($sql);
$q2->bindParam(':country', $country);
$q2->bindParam(':base', $res);
$q2->execute();
//echo $res;
return $res;
}
else
{
$query->closeCursor();
$this->fillMap($country,$fdata);
return $fdata;
}
}
现在我的问题是,当使用php锁定表时,如何解锁表映射?
我还需要说明的是,我在读取xml之前启动事务,并在完成所有操作后提交,所以当映射可能未锁定时,事务将等待大约2分钟。这可能是我得到超时错误的原因,我可以将其移动到循环中或更改mysql超时
编辑详细代码:
选中$this->getMap();什么是最常用的桌子
function sendOddsToDb(){
try{
$this->conn->connect();
$this->PDO->beginTransaction();
$countries = $this->OddCountries;
$stmt = $this->PDO->prepare($this->insOdds);
//$dbempty = $this->countRows('odds');
//$this->clrLeagues();
foreach($countries as $country){
$path = "{$this->base}/feeds/odds/{$country}odds.xml";
$odds_feed = $this->parser->parseFile($path);
$fupddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$newcountry = '';
if(isset($odds_feed->league)){
$newcountry = $odds_feed->league->attributes()->country;
$fcountries = $this->filterCountries($newcountry);
echo $fcountries . '<br>';
$sql = "select UpdatedDate from odds where Country = '{$fcountries}' order by UpdatedDate desc limit 1";
$res = $this->PDO->query($sql);
$dbupd = date('Y-m-d H:i:s',strtotime($res->fetchColumn()));
if(!$this->sameUpdated($fupddate,$dbupd)){
foreach($odds_feed->league as $league){ //za svaku ligu u fidu
$subid = $league->attributes()->sub_id;
$sportname = '';
$sportid = 0;
if($odds_feed->attributes()->sport == 'soccer' || $odds_feed->attributes()->sport == 'football'){
$sportname = 'football';
$sportid = 1;
}
else{
$sportname = NULL;
}
$lg2 = '';
$lg = $league->attributes()->name;
$ctr = $league->attributes()->country.':';
if(!contains(strtolower($lg),strtolower($ctr))){
$lg2 = ucfirst($ctr) . ' ' . ucfirst($lg);
}
else{
$lg2 = $league->attributes()->name;
}
$flg = $this->getMap2($lg2);
$this->sendLeaguesToDb($league->attributes()->id, $flg ,$fcountries,$sportid,$subid,'tipgin');
foreach($league->match as $match){
$dbdate = date('Y-m-d',strtotime($match->attributes()->date));
$updateddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$dbtime = date('H:i:s', strtotime($match->attributes()->time));
$datetime = date('Y-m-d H:i:s',strtotime($dbdate . $dbtime));
$hteam = $this->getMap($fcountries,toShort($match->home->attributes()->name));
$ateam = $this->getMap($fcountries,toShort($match->away->attributes()->name));
//echo $hteam . ' ' . $ateam;
$fixid = 0;
if($match->attributes()->id == 0 || $match->attributes()->id == ''){
if($match->attributes()->alternate_id == 0 || $match->attributes()->id == ''){
$fixid = $match->attributes()->alternate_id_2;
}
else{
$fixid = $match->attributes()->alternate_id;
}
}
else{
$fixid = $match->attributes()->id;
}
//$m = $hteam . ' ' . $ateam;
//var_dump('MATCH: ' . $m . ' HTEAM: ' . mb_detect_encoding($hteam). ' ATEAM: ' . mb_detect_encoding($ateam));
if($match->odds != NULL or $match->odds != ''){
foreach ($match->odds as $odds) {
//var_dump($odd);
if($odds->type != NULL or $odds->type != ''){
foreach ($odds->type as $type) {
if($type->bookmaker != NULL or $type->bookmaker != ''){
foreach ($type->bookmaker as $bookmaker) {
//$oldbook = ;
if($bookmaker->attributes()->name != 'BetClick'){
if($bookmaker->attributes()->name != 'Bodog'){
if($bookmaker->attributes()->name != 'YouWin'){
$homeodds = NULL;
$drawodds = NULL;
$awayodds = NULL;
$numodds = NULL;
$dbhandicap = NULL;
$id2 = '0';
$typename = $this->getMap2($type->attributes()->name);
$fbooks = $this->filterBooks($bookmaker->attributes()->name);
if($typename == 'Over/Under' || $typename == 'Over/Under 1st Half' || $typename == 'Over/Under 2nd Half'){
foreach ($bookmaker->total as $total) { //daj kvote za svaki mec
$numodds = $total->attributes()->name;
foreach($total->odd as $odd){
switch ($odd->attributes()->name) {
case 'Over':
$homeodds = $odd->attributes()->value;
break;
case 'Under':
$awayodds = $odd->attributes()->value;
break;
}
$id2 = $numodds;
}
//echo "HOME TEAM: {$hteam} <BR>";
//echo "AWAY TEAM: {$ateam} <BR>";
/*
echo 'IF ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename} BOOK: {$fbooks} ID2: {$id2}" . "<br>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);
}
}
else if($typename == 'Handicap' || $typename == '3Way Handicap'){
$homeodds = array();
$drawodds = array();
$awayodds = array();
$arrhandicap = array();
$fhandicap = '';
foreach ($bookmaker->handicap as $handicap) { //daj kvote za svaki mec
if (strpos($handicap->attributes()->name,'+') !== false) {
$fhandicap = str_replace('+','',(string)$handicap->attributes()->name);
}else{
$fhandicap = (string)$handicap->attributes()->name;
}
$newhandi = '';
foreach($handicap->odd as $odd){
//$odd = $handicap->odd;
switch ($odd->attributes()->name) {
case '1':
$newhandi = (string)$fhandicap;
$homeodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case 'X':
$newhandi = $fhandicap;
$drawodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case '2':
if (strpos($fhandicap,'-') !== false) { //if negative
$newhandi = str_replace('-','',(string)$fhandicap); //to positive
//echo 'NEGATIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
elseif($fhandicap=='0'){
$newhandi = '0';
}
else{ //if positive
$newhandi = '-' . (string)$fhandicap; //to negative
//echo 'POSITIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
$awayodds[(string)$newhandi] = (string)$odd->attributes()->value;
break;
}
$arrhandicap[] = (string)$newhandi;
}
}
//print_r($arrhandicap);
//$arrhandicap[] = sort($dbhandicap);
$inhand = '';
$varhome = '';
$vardraw = '';
$varaway = '';
foreach($arrhandicap as $hand){
$inhand = (string)$hand;
if(isset($hand)){
//echo $typename. ': ' . $hand . '<br>';
if((array_key_exists($inhand,$homeodds)) && (isset($homeodds[$inhand]))){
$varhome = $homeodds[$inhand];
}
if((array_key_exists($inhand,$awayodds)) && (isset($awayodds[$inhand]))){
$varaway = $awayodds[$inhand];
}
if((array_key_exists($inhand,$drawodds)) && (isset($drawodds[$inhand]))){
$vardraw = $drawodds[$inhand];
}
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$varhome,
$vardraw,$varaway, $fbooks,
$bookmaker->attributes()->id, $hand, $hand);
/*echo 'ELSEIF ID: ' . $match->attributes()->id . $league->attributes()->country . " HOMEODDS: {$varhome} DRAW: {$vardraw} AWAYODDS: {$varaway} TYPE: {$typename} BOOK: {$fbooks} ID2: {$inhand}" . "<br>";
*/}
}
}
else{
foreach ($bookmaker->odd as $odd) { //daj kvote za svaki mec
if($typename == 'Home/Away'){
$typename = 'Draw No Bet';
}
switch ($odd->attributes()->name) {
case '1':
case '1X':
case 'Yes':
$homeodds = $odd->attributes()->value;
break;
case 'X':
case 'X2':
$drawodds = $odd->attributes()->value;
break;
case '2':
case '12':
case 'No':
$awayodds = $odd->attributes()->value;
break;
}
$id2 = 0;
//echo 'ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename} BOOK: {$fbooks} ID2: {$id2}" . "<br>";
}
/*
echo "ELSE HOME TEAM: {$hteam} <BR>";
echo "ELSE AWAY TEAM: {$ateam} <BR>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);
}
}
}
}
}
}
}
}
}
}
}
}
}
//echo $country.'<br>';
}
}
$this->PDO->commit(); //SAVE
$this->conn->close();
}
catch(Exception $e){
//echo $e;
}
}
private function execOdds($stmt, $matchid, $upddate, $type, $country, $league, $leagueid, $subid, $cup, $sport, $hteam, $hteamid, $ateam, $ateamid, $datetime, $date, $time, $status, $numodds, $homeodds, $drawodds, $awayodds, $book, $bookid, $handicap, $id2){
$event = $hteam . ' - ' . $ateam;
$fcountry = $country;
$fleague = $league;
$stmt->bindParam(':fixturematchid', $matchid);$stmt->bindParam(':updateddate',$upddate);$stmt->bindParam(':type',$type);
$stmt->bindParam(':country',$fcountry);$stmt->bindParam(':league',$fleague);$stmt->bindParam(':leagueid',$leagueid);
$stmt->bindParam(':subid',$subid);
$stmt->bindParam(':cup',$cup);$stmt->bindParam(':eventname',$event);$stmt->bindParam(':sportname',$sport);
$stmt->bindParam(':hometeam', $hteam);$stmt->bindParam(':hometeamid', $hteamid);$stmt->bindParam(':awayteam', $ateam);
$stmt->bindParam(':awayteamid', $ateamid);$stmt->bindParam(':datetime',$datetime);$stmt->bindParam(':date',$date);
$stmt->bindParam(':time',$time);$stmt->bindParam(':status',$status);$stmt->bindParam(':numodds', $numodds);
$stmt->bindParam(':homeodds', $homeodds);$stmt->bindParam(':drawodds',$drawodds);$stmt->bindParam(':awayodds',$awayodds);
$stmt->bindParam(':bookmaker',$book);$stmt->bindParam(':bookmakerid',$bookid);$stmt->bindParam(':handicap', $handicap);
$stmt->bindParam(':id2', $id2);
$stmt->execute(); //EXEC*/
}
函数sendOddsToDb(){
试一试{
$this->conn->connect();
$this->PDO->beginTransaction();
$countries=$this->OddCountries;
$stmt=$this->PDO->prepare($this->insOdds);
//$dbempty=$this->countRows(“赔率”);
//$this->clrLeagues();
foreach($国家作为$国家){
$path=“{$this->base}/feeds/bits/{$country}bits.xml”;
$doffics\u feed=$this->parser->parseFile($path);
$fupddate=date('Y-m-dh:i:s',strotime($doptions\u feed->attributes()->updated));
$newcountry='';
如果(isset($赔率->联盟)){
$newcountry=$prospects\u feed->league->attributes()->country;
$fccountries=$this->filterCountries($newcountry);
回显$fccountries.“
”;
$sql=“根据UpdatedDate desc limit 1从赔率中选择UpdatedDate,其中国家=“{$FCcountries}”顺序;
$res=$this->PDO->query($sql);
$dbupd=date('Y-m-dh:i:s',strottime($res->fetchColumn());
如果(!$this->sameUpdated($fupddate,$dbupd)){
foreach($赔率\饲料->联盟为$联盟){//za svaku ligu fidu
$subid=$league->attributes()->sub_id;
$sportname='';
$sportid=0;
如果($bits_feed->attributes()->sport='soccer'| |$bits_feed->attributes()->sport='football'){
$sportname='football';
$sportid=1;
}
否则{
$sportname=NULL;
}
$lg2='';
$lg=$league->attributes()->name;
$ctr=$league->attributes()->country.':';
如果(!包含(strtolower($lg),strtolower($ctr))){
$lg2=ucfirst($ctr)。“”.ucfirst($lg);
}
否则{
$lg2=$league->attributes()->name;
}
$flg=$this->getMap2($lg2);
$this->sendLeaguesToDb($league->attributes()->id,$flg,$fccountries,$sportid,$subid,'tipgin');
foreach($league->match as$match){
$dbdate=date('Y-m-d',strottime($match->attributes()->date));
$UpdateDate=date('Y-m-d H:i:s',strottime($赔率饲料->属性()->更新));
$dbtime=date('H:i:s',strottime($match->attributes()->time));
$datetime=date('Y-m-dh:i:s',strottime($dbdate.$dbtime));
$hteam=$this->getMap($fccountries,toShort($match->home->attributes()->name));
$ateam=$this->getMap($fccountries,toShort($match->away->attributes()->name));
//echo$hteam.'.$ateam;
$fixid=0;
如果($match->attributes()->id==0 | |$match->attributes()->id==''){
如果($match->attributes()->alternate|u id==0 ||$match->attributes()->id==0){
$fixid=$match->attributes()->alternate_id_2;
}
否则{
$fixid=$match->attributes()->alternate\u id;
}
}
否则{
$fixid=$match->attributes()->id;
}
//$m=$hteam.'.$ateam;
//var_dump('MATCH:'.$m。'HTEAM:'.mb_detect_encoding($HTEAM)。'ATEAM:'.mb_detect_encoding($ATEAM));
如果($match->赔率!=NULL或$match->赔率!=''){
foreach($match->赔率为$赔率){
//var_dump(奇数美元);
如果($bits->type!=NULL或$bits->type!=''){
foreach($doffers->type as$type){
如果($type->bookmaker!=NULL或$type->bookmaker!=''){
foreach($type->bookmaker作为$bookmaker){
//$oldbook=;
如果($bookmaker->attributes()->name!='BetClick'){
如果($bookmaker->attributes()->name!='Bodog'){
如果($bookmaker->attributes()->name!='YouWin'){
$homeodds=NULL;
$drawLobbits=NULL;
$awayods=NULL;
$numods=NULL;
$dbdifficia=NULL;
$id2='0';
$typename=$this->getMap2($type->attributes()->name);
$fbooks=$this->filterBooks($bookmaker->attributes()->name);
如果($typename=='Over/Under'| |$typename=='Over/Under first Half'| |$typename=='Over/Under hend Half'){
foreach($bookmaker->total as$total){//daj kvote za svaki mec
$numods=$total->attributes()->name;
function sendOddsToDb(){
try{
$this->conn->connect();
$this->PDO->beginTransaction();
$countries = $this->OddCountries;
$stmt = $this->PDO->prepare($this->insOdds);
//$dbempty = $this->countRows('odds');
//$this->clrLeagues();
foreach($countries as $country){
$path = "{$this->base}/feeds/odds/{$country}odds.xml";
$odds_feed = $this->parser->parseFile($path);
$fupddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$newcountry = '';
if(isset($odds_feed->league)){
$newcountry = $odds_feed->league->attributes()->country;
$fcountries = $this->filterCountries($newcountry);
echo $fcountries . '<br>';
$sql = "select UpdatedDate from odds where Country = '{$fcountries}' order by UpdatedDate desc limit 1";
$res = $this->PDO->query($sql);
$dbupd = date('Y-m-d H:i:s',strtotime($res->fetchColumn()));
if(!$this->sameUpdated($fupddate,$dbupd)){
foreach($odds_feed->league as $league){ //za svaku ligu u fidu
$subid = $league->attributes()->sub_id;
$sportname = '';
$sportid = 0;
if($odds_feed->attributes()->sport == 'soccer' || $odds_feed->attributes()->sport == 'football'){
$sportname = 'football';
$sportid = 1;
}
else{
$sportname = NULL;
}
$lg2 = '';
$lg = $league->attributes()->name;
$ctr = $league->attributes()->country.':';
if(!contains(strtolower($lg),strtolower($ctr))){
$lg2 = ucfirst($ctr) . ' ' . ucfirst($lg);
}
else{
$lg2 = $league->attributes()->name;
}
$flg = $this->getMap2($lg2);
$this->sendLeaguesToDb($league->attributes()->id, $flg ,$fcountries,$sportid,$subid,'tipgin');
foreach($league->match as $match){
$dbdate = date('Y-m-d',strtotime($match->attributes()->date));
$updateddate = date('Y-m-d H:i:s',strtotime($odds_feed->attributes()->updated));
$dbtime = date('H:i:s', strtotime($match->attributes()->time));
$datetime = date('Y-m-d H:i:s',strtotime($dbdate . $dbtime));
$hteam = $this->getMap($fcountries,toShort($match->home->attributes()->name));
$ateam = $this->getMap($fcountries,toShort($match->away->attributes()->name));
//echo $hteam . ' ' . $ateam;
$fixid = 0;
if($match->attributes()->id == 0 || $match->attributes()->id == ''){
if($match->attributes()->alternate_id == 0 || $match->attributes()->id == ''){
$fixid = $match->attributes()->alternate_id_2;
}
else{
$fixid = $match->attributes()->alternate_id;
}
}
else{
$fixid = $match->attributes()->id;
}
//$m = $hteam . ' ' . $ateam;
//var_dump('MATCH: ' . $m . ' HTEAM: ' . mb_detect_encoding($hteam). ' ATEAM: ' . mb_detect_encoding($ateam));
if($match->odds != NULL or $match->odds != ''){
foreach ($match->odds as $odds) {
//var_dump($odd);
if($odds->type != NULL or $odds->type != ''){
foreach ($odds->type as $type) {
if($type->bookmaker != NULL or $type->bookmaker != ''){
foreach ($type->bookmaker as $bookmaker) {
//$oldbook = ;
if($bookmaker->attributes()->name != 'BetClick'){
if($bookmaker->attributes()->name != 'Bodog'){
if($bookmaker->attributes()->name != 'YouWin'){
$homeodds = NULL;
$drawodds = NULL;
$awayodds = NULL;
$numodds = NULL;
$dbhandicap = NULL;
$id2 = '0';
$typename = $this->getMap2($type->attributes()->name);
$fbooks = $this->filterBooks($bookmaker->attributes()->name);
if($typename == 'Over/Under' || $typename == 'Over/Under 1st Half' || $typename == 'Over/Under 2nd Half'){
foreach ($bookmaker->total as $total) { //daj kvote za svaki mec
$numodds = $total->attributes()->name;
foreach($total->odd as $odd){
switch ($odd->attributes()->name) {
case 'Over':
$homeodds = $odd->attributes()->value;
break;
case 'Under':
$awayodds = $odd->attributes()->value;
break;
}
$id2 = $numodds;
}
//echo "HOME TEAM: {$hteam} <BR>";
//echo "AWAY TEAM: {$ateam} <BR>";
/*
echo 'IF ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename} BOOK: {$fbooks} ID2: {$id2}" . "<br>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);
}
}
else if($typename == 'Handicap' || $typename == '3Way Handicap'){
$homeodds = array();
$drawodds = array();
$awayodds = array();
$arrhandicap = array();
$fhandicap = '';
foreach ($bookmaker->handicap as $handicap) { //daj kvote za svaki mec
if (strpos($handicap->attributes()->name,'+') !== false) {
$fhandicap = str_replace('+','',(string)$handicap->attributes()->name);
}else{
$fhandicap = (string)$handicap->attributes()->name;
}
$newhandi = '';
foreach($handicap->odd as $odd){
//$odd = $handicap->odd;
switch ($odd->attributes()->name) {
case '1':
$newhandi = (string)$fhandicap;
$homeodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case 'X':
$newhandi = $fhandicap;
$drawodds[(string)$newhandi] =
(string)$odd->attributes()->value;
break;
case '2':
if (strpos($fhandicap,'-') !== false) { //if negative
$newhandi = str_replace('-','',(string)$fhandicap); //to positive
//echo 'NEGATIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
elseif($fhandicap=='0'){
$newhandi = '0';
}
else{ //if positive
$newhandi = '-' . (string)$fhandicap; //to negative
//echo 'POSITIVE - OLD: ' . $fhandicap . ' NEW: '.$newhandi . '<br>';
}
$awayodds[(string)$newhandi] = (string)$odd->attributes()->value;
break;
}
$arrhandicap[] = (string)$newhandi;
}
}
//print_r($arrhandicap);
//$arrhandicap[] = sort($dbhandicap);
$inhand = '';
$varhome = '';
$vardraw = '';
$varaway = '';
foreach($arrhandicap as $hand){
$inhand = (string)$hand;
if(isset($hand)){
//echo $typename. ': ' . $hand . '<br>';
if((array_key_exists($inhand,$homeodds)) && (isset($homeodds[$inhand]))){
$varhome = $homeodds[$inhand];
}
if((array_key_exists($inhand,$awayodds)) && (isset($awayodds[$inhand]))){
$varaway = $awayodds[$inhand];
}
if((array_key_exists($inhand,$drawodds)) && (isset($drawodds[$inhand]))){
$vardraw = $drawodds[$inhand];
}
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$varhome,
$vardraw,$varaway, $fbooks,
$bookmaker->attributes()->id, $hand, $hand);
/*echo 'ELSEIF ID: ' . $match->attributes()->id . $league->attributes()->country . " HOMEODDS: {$varhome} DRAW: {$vardraw} AWAYODDS: {$varaway} TYPE: {$typename} BOOK: {$fbooks} ID2: {$inhand}" . "<br>";
*/}
}
}
else{
foreach ($bookmaker->odd as $odd) { //daj kvote za svaki mec
if($typename == 'Home/Away'){
$typename = 'Draw No Bet';
}
switch ($odd->attributes()->name) {
case '1':
case '1X':
case 'Yes':
$homeodds = $odd->attributes()->value;
break;
case 'X':
case 'X2':
$drawodds = $odd->attributes()->value;
break;
case '2':
case '12':
case 'No':
$awayodds = $odd->attributes()->value;
break;
}
$id2 = 0;
//echo 'ID: ' . $match->attributes()->alternate_id_2 . $league->attributes()->country . " ODDS: {$homeodds} {$drawodds} {$awayodds} TYPE: {$typename} BOOK: {$fbooks} ID2: {$id2}" . "<br>";
}
/*
echo "ELSE HOME TEAM: {$hteam} <BR>";
echo "ELSE AWAY TEAM: {$ateam} <BR>";
*/
$this->execOdds($stmt, $fixid, $updateddate,
$typename, $fcountries,$league->attributes()->name,
$league->attributes()->id, $subid, $league->attributes()->cup,$sportname,
$hteam,$match->home->attributes()->id,
$ateam,$match->away->attributes()->id, $datetime, $dbdate,
$dbtime, $match->attributes()->status, $numodds,$homeodds,$drawodds,
$awayodds, $fbooks, $bookmaker->attributes()->id, $dbhandicap, $id2);
}
}
}
}
}
}
}
}
}
}
}
}
}
//echo $country.'<br>';
}
}
$this->PDO->commit(); //SAVE
$this->conn->close();
}
catch(Exception $e){
//echo $e;
}
}
private function execOdds($stmt, $matchid, $upddate, $type, $country, $league, $leagueid, $subid, $cup, $sport, $hteam, $hteamid, $ateam, $ateamid, $datetime, $date, $time, $status, $numodds, $homeodds, $drawodds, $awayodds, $book, $bookid, $handicap, $id2){
$event = $hteam . ' - ' . $ateam;
$fcountry = $country;
$fleague = $league;
$stmt->bindParam(':fixturematchid', $matchid);$stmt->bindParam(':updateddate',$upddate);$stmt->bindParam(':type',$type);
$stmt->bindParam(':country',$fcountry);$stmt->bindParam(':league',$fleague);$stmt->bindParam(':leagueid',$leagueid);
$stmt->bindParam(':subid',$subid);
$stmt->bindParam(':cup',$cup);$stmt->bindParam(':eventname',$event);$stmt->bindParam(':sportname',$sport);
$stmt->bindParam(':hometeam', $hteam);$stmt->bindParam(':hometeamid', $hteamid);$stmt->bindParam(':awayteam', $ateam);
$stmt->bindParam(':awayteamid', $ateamid);$stmt->bindParam(':datetime',$datetime);$stmt->bindParam(':date',$date);
$stmt->bindParam(':time',$time);$stmt->bindParam(':status',$status);$stmt->bindParam(':numodds', $numodds);
$stmt->bindParam(':homeodds', $homeodds);$stmt->bindParam(':drawodds',$drawodds);$stmt->bindParam(':awayodds',$awayodds);
$stmt->bindParam(':bookmaker',$book);$stmt->bindParam(':bookmakerid',$bookid);$stmt->bindParam(':handicap', $handicap);
$stmt->bindParam(':id2', $id2);
$stmt->execute(); //EXEC*/
}