->connect()
Connects to a local or remote database endpoint.
Method Syntax$db->connect(url, options)
Arguments | Description | ||
---|---|---|---|
url | The url of the database endpoint to connect to. | ||
options | An object with options to initiate the connection to SurrealDB. |
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.
// Connect to a local endpoint $db->connect('http://127.0.0.1:8000/rpc'); // Connect to a remote endpoint $db->connect('https://cloud.surrealdb.com/rpc'); // Specify a namespace and database pair to use $db->connect('https://cloud.surrealdb.com/rpc', [ "namespace" => "surrealdb", "database" => "docs", ]);