php 否毗邻至 aws dynamodb、azure cosmos db 以及 谷歌 cloud sql,办法如高:aws dynamodb:应用 dynamodbclient 类。azure cosmos db:利用 tablerestproxy 类。谷歌 cloud sql:应用 pdo 联接。

使用 PHP 连接到云数据库:AWS DynamoDB、Azure Cosmos DB、Google Cloud SQL

运用 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的具体形式,更多请存眷萤水红IT仄台此外相闭文章!

点赞(30) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部