Portál AbcLinuxu, 3. listopadu 2025 07:51
$stmt = $pdo->prepare('INSERT INTO table (a, b, c, d) VALUES (?, ?, ?, ?);');
$stmt->execute(array($a, $b, $c, $d));
Řešení dotazu:
$stmt = $pdo->prepare('INSERT INTO table (a, b, c, d) VALUES (?, ?, ?, ?);');
try {
$stmt->execute(array($a, $b, $c, $d));
} catch (PDOException $e) {
if ($e->errorInfo[1] == 1062) {
// Chyba: duplicate entry
} else {
// Nějaká jiná chyba
}
}
errorInfo[1], které je MySQL-specific, a používat standardizované SQLSTATE:
if ($e->getCode() == "23000").
Děkuji
try ... catch blok? ;)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.