->connect()
Connects to a local or remote database endpoint.
Method Syntax
$db->connect($host, $options)
Arguments
| Arguments | Type | Description |
|---|
host | string | The url of the database endpoint to connect to. |
options | associative array | An object with options to initiate the connection to SurrealDB. |
Example usage
There are several ways to connect to a database endpoint. You can connect to a local or remote endpoint, specify a namespace and database pair to use, authenticate with an existing token, authenticate using a pair of credentials, or use advanced custom logic to prepare the connection to the database.
$db->connect('http://127.0.0.1:8000/rpc');
$db->connect('https://cloud.surrealdb.com/rpc');
$db->connect('https://cloud.surrealdb.com/rpc', [
"namespace" => "surrealdb",
"database" => "docs",
]);