Scroll
Fehler protokollieren
Die Database API wirft bei Fehlern Ausnahmen, die abgefangen werden können, indem man Datenbankoperationen in try {} catch() {}-Blöcke einschließt, wie im folgenden Beispiel gezeigt:
// Die Transaktion beginnt hier. $txn = $connection->startTransaction(); try { $id = $connection->insert('example') ->fields([ 'field1' => 'mystring', 'field2' => 5, ]) ->execute(); my_other_function($id); return $id; } catch (Exception $e) { // Irgendwo ist etwas schiefgelaufen, daher jetzt zurückrollen. $txn->rollBack(); // Die Ausnahme im Watchdog protokollieren. \Drupal::logger('type')->error($e->getMessage()); }
Source URL:
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.