Connect with legacy drivers

DataStax does not support legacy drivers, which includes the PHP and Ruby drivers.

For the best experience, use supported native drivers to connect to an Astra DB database. For details about supported versions, see Version Compatibility.

Legacy drivers should be used only if migrating an existing Apache Cassandra® application developed with a Legacy driver to Astra DB.

Prerequisites

Legacy drivers were developed for Apache Cassandra®. To connect to Astra DB with a legacy driver, you must collect connection information from the database’s Secure Connect Bundle (SCB) and set up the required SSL context for your driver. If you use VPC peering, you can download an external SCB for use within your VPC peering. Alternatively, you can use the SSL-related files (ca.cert, cert, and key) and the port from the cqlshrc file.

  1. Download your database’s SCB.

  2. From the SCB, get the SSL-related files:

    • ca.cert

    • cert

    • key

  3. In the cqlshrc file, get the port.

    Use only the port from cqlshrc. Other ports in the SCB can’t support the legacy driver connection.

  4. In the config.json file, get the hostname.

PHP legacy driver

Use these steps to connect to Astra DB with the DataStax PHP driver:

  1. Install the DataStax PHP Driver for Cassandra.

  2. Get a Client ID and Client Secret by creating an application token.

  3. Copy the certificate files from the Astra DB SCB to /etc/ssl/certs/astra-secure-connect. This folder should contain the ca.cert, cert, and key files.

  4. Create a PHP script file, and then enter the following code:

    <?php
    
    $ssl     = Cassandra::ssl()
                   \->withTrustedCerts('/etc/ssl/certs/astra-secure-connect/ca.cert')
                   \->withClientCert('/etc/ssl/certs/astra-secure-connect/cert')
                   \->withPrivateKey('/etc/ssl/certs/astra-secure-connect/key')
                   \->build();
    
    
    $cluster = Cassandra::cluster()
                   \->withSSL($ssl)
                   \->withCredentials("CLIENT_ID", "CLIENT_SECRET")
                   \->withContactPoints('HOSTNAME')
                   \->withPort(PORT)
                   \->build();
    
    $session = $cluster\->connect();
    
    $result = $session\->execute('SELECT keyspace_name, table_name FROM system_schema.tables');
    
    foreach ($result as $row) {
        printf("The keyspace "%s" has a table "%s".
        ", $row['keyspace_name'], $row['table_name']);
    }"

    Replace the following:

    • HOSTNAME: Your Astra DB database hostname, such as DB_ID-REGION_NAME.db.astra.datastax.com.

    • PORT: Your Astra DB database port.

    • CLIENT_ID and CLIENT_SECRET**: The Client ID and Client Secret from your application token.

Ruby legacy driver

Use these steps to connect to Astra DB with the DataStax Ruby driver:

  1. Install the DataStax Ruby Driver for Cassandra.

  2. Copy the certificate files from the Astra DB SCB to /etc/ssl/certs/astra-secure-connect. This folder should contain the ca.cert, cert, and key files.

  3. Create a Ruby script file, and then enter the following code:

    require 'cassandra'
    
    cluster = Cassandra.cluster(
                username: 'CLIENT_ID',
                password: 'CLIENT_SECRET',
                hosts: ['HOSTNAME'],
                port: PORT,
                server_cert: '/etc/ssl/certs/astra-secure-connect/ca.cert',
                client_cert: '/etc/ssl/certs/astra-secure-connect/cert',
                private_key: '/etc/ssl/certs/astra-secure-connect/key'
    )
    
    keyspace = 'system_schema'
    session  = cluster.connect(keyspace) # create session, optionally scoped to a keyspace, to execute queries
    
    future = session.execute_async('SELECT keyspace_name, table_name FROM tables') # fully asynchronous api
    future.on_success do |rows|
      rows.each do |row|
        puts "The keyspace #{row['keyspace_name']} has a table #{row['table_name']}"
      end
    end
    future.join

    Replace the following:

    • HOSTNAME: Your Astra DB database hostname, such as DB_ID-REGION_NAME.db.astra.datastax.com.

    • PORT: Your Astra DB database port.

    • CLIENT_ID and CLIENT_SECRET**: The Client ID and Client Secret from your application token.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com