Scroll
Beleženje grešaka
Database API baca izuzetke pri grešci, koje možete uhvatiti tako što ćete obaviti baze podataka unutar try {} catch() {} blokova, kao što je prikazano u ovom primeru:
// Transakcija se otvara ovde. $txn = $connection->startTransaction(); try { $id = $connection->insert('example') ->fields([ 'field1' => 'mystring', 'field2' => 5, ]) ->execute(); my_other_function($id); return $id; } catch (Exception $e) { // Nešto je pošlo po zlu, pa izvršavamo rollback. $txn->rollBack(); // Zabeleži izuzetak u watchdog. \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.