Connect with legacy drivers
|
DataStax does not support legacy drivers, which includes the PHP and Ruby drivers. For the best experience, use supported drivers to connect to Astra Managed Cluster databases. For details about supported drivers and versions, see Cassandra drivers supported by DataStax. Only use legacy drivers to migrate an existing Apache Cassandra® application that was developed with a legacy driver to Managed Cluster databases. |
Prerequisites
Legacy drivers were developed for Apache Cassandra®.
To connect to Managed Cluster databases 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.
PHP legacy driver
Use these steps to connect to a Managed Cluster database with the PHP driver:
-
Install the PHP Driver for Cassandra.
-
Get a Client ID and Client Secret by creating an application token.
-
Copy the certificate files from the SCB to
/etc/ssl/certs/astra-secure-connect. This folder should contain theca.cert,cert, andkeyfiles. -
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 database’s hostname, such asDB_ID-REGION_NAME.db.astra.datastax.com. -
PORT: Your database’s port. -
CLIENT_IDandCLIENT_SECRET**: The Client ID and Client Secret from your application token.
-
Ruby legacy driver
Use these steps to connect to a Managed Cluster database with the Ruby driver:
-
Install the Ruby Driver for Cassandra.
-
Copy the certificate files from the SCB to
/etc/ssl/certs/astra-secure-connect. This folder should contain theca.cert,cert, andkeyfiles. -
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.joinReplace the following:
-
HOSTNAME: Your database’s hostname, such asDB_ID-REGION_NAME.db.astra.datastax.com. -
PORT: Your database’s port. -
CLIENT_IDandCLIENT_SECRET**: The Client ID and Client Secret from your application token.
-