У меня есть 2 таблицы, для которых, например, потребуется 4 обновления или вставка кортежей
Таблица будет иметь запись для игры и карьеры для каждого игрока (2), то есть 4 кортежа. Вдобавок ко всему, я могу думать только о том, чтобы сделать SELECT для player1 и игры, если она не существует, вставить еще обновление, theh для player1 и карьеры ....... лучший способ справиться с этим? В PHP PDO MYSQL существующий код:
CREATE TABLE `standings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`league_id` int(11) NOT NULL,
`season_id` int(11) NOT NULL,
`team_id` int(11) NOT NULL,
`statistic_type_id` int(11) NOT NULL,
`wlt` varchar(30) NOT NULL);
$sth = $dbh->prepare('Select * from standings
where league_id=? and season_id=? and team_id=? and statistic_type_id=$? ');
$data = $sth->execute(array($l, $s, $t, $st));
$data = $sth->fetchAll();
if ($sth->rowCount() == 0) {
$wlt = $w . '," . $lo . ',' . $di;
$sth = $dbh->prepare('INSERT INTO standings ( id, league_id, season_id,
team_id, statistic_type_id, wlt)
VALUES( 0, ?, ?, ?, ?, ?);
$data = $sth->execute(array( $l, $s, $t, $st, $wlt));
} else {
foreach ($data as $row) {
$wlt = explode(",", $row['wlt']);
$wlt[0] = $wlt[0] + $w;
$wlt[1] = $wlt[1] + $lo;
$wlt[2] = $wlt[2] + $di;
$nwlt = implode(",", $wlt);
$sth = $dbh->prepare('UPDATE standings SET wlt=?
where league_id=? and season_id=? and team_id=? and statistic_type_id=$? ');
$data = $sth->execute(array($nwlt, $l, $s, $t, $st));
}
}