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 DynamoDBuse 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 DBuse 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 SQLuse 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的详细内容,更多请关注知识资源分享宝库其它相关文章!
发表评论