Connect to cloud databases using PHP: AWS DynamoDB, Azure Cosmos DB, Google Cloud SQL

PHPz
Release: 2024-06-06 11:21:57
Original
552 people have browsed it

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.

使用 PHP 连接到云数据库:AWS DynamoDB、Azure Cosmos DB、Google Cloud SQL

Use PHP to connect to cloud databases: AWS DynamoDB, Azure Cosmos DB, Azure Cosmos DB, Google Cloud SQL

AWS DynamoDB

use Aws\DynamoDb\DynamoDbClient; $client = new DynamoDbClient([ 'region' => 'us-east-1', 'credentials' => [ 'key' => 'your-access-key', 'secret' => 'your-secret-key', ], ]);
Copy after login

Azure Cosmos DB

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);
Copy after login

Google Cloud SQL

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(); }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!