A newer version of this documentation is available.

View Latest

Managing Connections using the PHP SDK with Couchbase Server

  • how-to
    This section describes how to connect the PHP SDK to a Couchbase cluster. It contains best practices as well as information on TLS/SSL and other advanced connection options.

    Connecting to a Cluster

    A connection to a Couchbase Server cluster is represented by a cluster object. A cluster provides access to Buckets, Scopes, and Collections, as well as various Couchbase services and management interfaces. The simplest way to create a Cluster object is to call a new connectionString with a username and password:

    $connectionString = "couchbase://localhost";
    $opts = new \Couchbase\ClusterOptions();
    $opts->credentials("Administrator", "password");
    $cluster = new \Couchbase\Cluster($connectionString, $opts);
    If you are connecting to a version of Couchbase Server older than 6.5, it will be more efficient if the addresses are those of data (KV) nodes. You will in any case, with 6.0 and earlier, need to open a Bucket instance before connecting to any other HTTP services (such as Query or Search.

    Connection strings and the __construct() method are covered in the API guide.