Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
SqlCommand.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\db;
4
6
7class SqlCommand {
8
9 public static function executeSQLTransaction(string $activeDbOffset, string $sql): bool {
10 $db = DAO::getDatabase($activeDbOffset ?? 'default');
11 if (! $db->isConnected()) {
12 $db->setDbName('');
13 $db->connect();
14 }
15 if ($db->beginTransaction()) {
16 try {
17 $db->execute($sql);
18 if ($db->inTransaction()) {
19 $db->commit();
20 }
21 return true;
22 } catch (\Error $e) {
23 if ($db->inTransaction()) {
24 $db->rollBack();
25 }
26 return false;
27 }
28 } else {
29 $db->execute($sql);
30 return true;
31 }
32 }
33}
static executeSQLTransaction(string $activeDbOffset, string $sql)
Definition SqlCommand.php:9
Gateway class between database and object model.
Definition DAO.php:33
static connect($offset, $wrapper, $dbType, $dbName, $serverName='127.0.0.1', $port='3306', $user='root', $password='', $options=[], $cache=false)
Establishes the connection to the database using the past parameters.
Definition DAO.php:230
Database implementation.