Open a TCP connection to Cloud SQL PostgreSQL by using the PHP Data Objects (PDO) extension.
Documentation pages that include this code sample
To view the code sample used in context, see the following documentation:
- Connect using the Cloud SQL Auth proxy
- Connecting from App Engine flexible environment to Cloud SQL
- Connecting from App Engine standard environment to Cloud SQL
- Connecting from Cloud Functions to Cloud SQL
- Connecting from Cloud Run to Cloud SQL
- Managing database connections
- Overview to connecting
// $username = 'your_db_user'; // $password = 'yoursupersecretpassword'; // $dbName = 'your_db_name'; // $dbHost = "127.0.0.1"; // Connect using TCP $dsn = sprintf('pgsql:dbname=%s;host=%s', $dbName, $dbHost); // Connect to the database $conn = new PDO($dsn, $username, $password, $connConfig);
To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.