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中文网其他相关文章!