• Start

Languages

/

PHP

/

Methods

connect

Connect to a local or remote database endpoint using the connect method in the SurrealDB PHP SDK.

Connects to a local or remote database endpoint.

Method Syntax

$db->connect($host, $options)
ArgumentsTypeDescription
host string The url of the database endpoint to connect to.
options associative array 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",
]);

Was this page helpful?