PHP 可連接至 AWS DynamoDB、Azure Cosmos DB 和 Google Cloud SQL,方法如下:AWS DynamoDB:使用 DynamoDbClient 類別。 Azure Cosmos DB:使用 TableRestProxy 類別。 Google Cloud SQL:使用 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(); }
以上是使用 PHP 連線到雲端資料庫:AWS DynamoDB、Azure Cosmos DB、Google Cloud SQL的詳細內容。更多資訊請關注PHP中文網其他相關文章!