Scroll
Գործառույթների գրանցման սխալներ
Տվյալների բազայի API-ն սխալի դեպքում նետում է բացառություններ, որոնք կարող են բռնվել, երբ տվյալների բազայի գործողությունները ներմուծվում են try {} catch() {} բլոկների մեջ, ինչպես ցույց է տրված այս օրինակով՝
// Տրանզակցիան բացվում է այստեղ։ $txn = $connection->startTransaction(); try { $id = $connection->insert('example') ->fields([ 'field1' => 'mystring', 'field2' => 5, ]) ->execute(); my_other_function($id); return $id; } catch (Exception $e) { // Հիշեք, որ ինչ-որ բան սխալ է եղել, այդ պատճառով հիմա կատարեք roll back։ $txn->rollBack(); // Գրանցեք բացառությունը 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.