PHP can connect to AWS DynamoDB, Azure Cosmos DB, and Google Cloud SQL as follows: AWS DynamoDB: Using the DynamoDbClient class. Azure Cosmos DB: Use the TableRestProxy class. Google Cloud SQL: Connect using PDO.
use Aws\DynamoDb\DynamoDbClient; $client = new DynamoDbClient([ 'region' => 'us-east-1', 'credentials' => [ 'key' => 'your-access-key', 'secret' => 'your-secret-key', ], ]);
use MicrosoftAzure\Storage\Table\TableRestProxy; $accountName = 'your-account-name'; $accountKey = 'your-account-key'; $tableName = 'your-table-name'; $connection = new TableRestProxy( $accountName, $accountKey, 'https://accountname.table.usgovcloudapi.net' ); $cloudTable = $connection->getTable($tableName);
use PDO; $username = 'your-username'; $password = 'your-password'; $database = 'your-database'; $host = 'your-host'; $socket = 'your-unix-socket'; try { $conn = new PDO( "mysql:dbname=$database;host=$host;unix_socket=$socket", $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] ); } catch (PDOException $e) { echo "Failed connecting to Google Cloud SQL: " . $e->getMessage(); }
The above is the detailed content of Connect to cloud databases using PHP: AWS DynamoDB, Azure Cosmos DB, Google Cloud SQL. For more information, please follow other related articles on the PHP Chinese website!