+ /**
+ * @brief Fetch the id of the last insert command
+ *
+ * @return integer Last inserted id
+ */
+ public static function lastInsertId() {
+ switch (self::$driver) {
+ case 'pdo':
+ $id = self::$db->lastInsertId();
+ break;
+ case 'mysqli':
+ $id = self::$db->insert_id;
+ break;
+ }
+ return $id;
+ }
+
+ /**
+ * @brief Locks a table for exclusive write access
+ *
+ * This function can be extended in the future to accept a table array as well.
+ *
+ * @param string $table Table name
+ *
+ * @return boolean was the lock successful?
+ */
+ public static function lock($table) {
+ // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
+ self::e("SET autocommit=0");
+ $success = self::e("LOCK TABLES `".self::escape($table)."` WRITE");
+ if (!$success) {
+ self::e("SET autocommit=1");
+ } else {
+ self::$in_transaction = true;
+ }
+ return $success;
+ }
+
+ /**
+ * @brief Unlocks all locked tables
+ *
+ * @return boolean was the unlock successful?
+ */
+ public static function unlock() {
+ // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
+ self::e("COMMIT");
+ $success = self::e("UNLOCK TABLES");
+ self::e("SET autocommit=1");
+ self::$in_transaction = false;
+ return $success;
+ }
+
+ /**
+ * @brief Starts a transaction
+ *
+ * @return boolean Was the command executed successfully?
+ */
+ public static function transaction() {
+ if (!self::e('COMMIT')) {
+ return false;
+ }
+ if (!self::e('START TRANSACTION')) {
+ return false;
+ }
+ self::$in_transaction = true;
+ return true;
+ }
+
+ /**
+ * @brief Does a commit
+ *
+ * @return boolean Was the command executed successfully?
+ */
+ public static function commit() {
+ if (!self::e('COMMIT')) {
+ return false;
+ }
+ self::$in_transaction = false;
+ return true;
+ }
+
+ /**
+ * @brief Does a rollback
+ *
+ * @return boolean Was the command executed successfully?
+ */
+ public static function rollback() {
+ if (!self::e('ROLLBACK')) {
+ return false;
+ }
+ self::$in_transaction = false;
+ return true;
+ }
+