Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php require_once 'vendor/autoload.php';
- class FirestoreDB {
- protected $database;
- protected $usermame;
- protected $password;
- protected $connection = null;
- /**
- * @param $database database path
- * @param $username username
- * @param $password password
- */
- public function __construct (string $database = '', string $username = '', string $password = '') {
- if (preg_match('/[^a-z_\-0-9]/i', $database)) {
- throw new InvalidArgumentException('$database (' . $database . ') has invalid character, allowed: a-z A-Z 0-9');
- }
- if (preg_match('/[^a-z_\-0-9]/i', $username)) {
- throw new InvalidArgumentException('$username (' . $username . ') has invalid character, allowed: a-z A-Z 0-9');
- }
- if (preg_match('/[^a-z_\-0-9]/i', $password)) {
- throw new InvalidArgumentException('$password (' . $password . ') has invalid character, allowed: a-z A-Z 0-9');
- }
- }
- /**
- * connect database
- *
- * @throws RuntimeException if cannot connect to database
- */
- public function connect () : void {
- try {
- $this->connection = ibase_connect (
- $this->database,
- $this->username,
- $this->password
- );
- } catch (Exception $e) {
- throw new RuntimeException('cannot connect to database: ' . $e->getMessage());
- }
- }
- /**
- * disconnect database
- */
- public function disconnect () : void {
- ibase_close($this->connection);
- }
- /**
- * check if connection is open and connected
- *
- * @return bool - if database is connected
- */
- public function is_connected () : bool {
- return ($this->connection === null) ? false : true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement