Heim  >  Artikel  >  Backend-Entwicklung  >  Stellen Sie mit PHP eine Verbindung zu Cloud-Datenbanken her: AWS DynamoDB, Azure Cosmos DB, Google Cloud SQL

Stellen Sie mit PHP eine Verbindung zu Cloud-Datenbanken her: AWS DynamoDB, Azure Cosmos DB, Google Cloud SQL

PHPz
PHPzOriginal
2024-06-06 11:21:57593Durchsuche

PHP kann wie folgt eine Verbindung zu AWS DynamoDB, Azure Cosmos DB und Google Cloud SQL herstellen: AWS DynamoDB: Verwendung der DynamoDbClient-Klasse. Azure Cosmos DB: Verwenden Sie die TableRestProxy-Klasse. Google Cloud SQL: Verbindung über PDO herstellen.

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

Verwenden Sie PHP zur Verbindung mit Cloud-Datenbanken: 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-access-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(
        "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();
}

Das obige ist der detaillierte Inhalt vonStellen Sie mit PHP eine Verbindung zu Cloud-Datenbanken her: AWS DynamoDB, Azure Cosmos DB, Google Cloud SQL. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn