php 可连接至 aws dynamodb、azure cosmos db 和 google cloud sql,方法如下:aws dynamodb:使用 dynamodbclient 类。azure cosmos db:使用 tablerestproxy 类。google cloud sql:使用 pdo 连接。
利用 PHP 连接至云数据库: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-<a style='color:#f60; text-decoration:underline;' href="https://www.php.cn/zt/16380.html" target="_blank">access</a>-key', 'secret' => 'your-secret-key', ], ]);
登录后复制
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);
登录后复制
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( "<a style='color:#f60; text-decoration:underline;' href="https://www.php.cn/zt/15713.html" target="_blank">mysql</a>: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中文网其它相关文章!