/** * Base method for performing an API call * @param $method * @param null $params * @param null $successCallback * @param null $errorCallback */ public function call($method, $params = null, $successCallback = null, $errorCallback = null) { if ($this->credentials && $method != "Authenticate") { $params["credentials"] = ["userName" => $this->credentials->getUsername(), "sessionId" => $this->credentials->getSessionId(), "database" => $this->credentials->getDatabase()]; } return $this->request($method, $params, $successCallback, $errorCallback); }
/** * Attempts to connect to database. * * @return void * @throws \RuntimeException */ private function connect() { $dsn = "{$this->credentials->getDriver()}:host={$this->credentials->getHost()}"; try { $pdo = new \PDO($dsn, $this->credentials->getUsername(), $this->credentials->getPassword()); } catch (\PDOException $e) { throw new \RuntimeException('Failed to connect to database.', 0, $e); } $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); $this->pdo = $pdo; if (!is_null($this->credentials->getCharset())) { $this->setCharset($this->credentials->getCharset()); } if (!is_null($this->credentials->getDatabase())) { $this->selectDatabase($this->credentials->getDatabase()); } }