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中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号