Syntax: driver:host=the-host-name;dbname=your-database-name
Data Source Name (DSN) specifies the host computer for the MySQL database and the name of the database.
Syntax: new PDO(dsn, username, password);
Assuming that you have already set up your PHP environment on GCP App Engine (this introduction uses Standard App Engine). If you have not set up your PHP environment on GCP App Engine or do not have Cloud SDK available, please refer to PHP deployment on GCP.
Also assume that you have already set up your Cloud SQL. If you have not set up your Cloud SQL, please refer to DB setup on GCP.
your-project-ID:us-east4:your-sql-instance-ID
(which is the SQL instance connection name)your-database-name
root
(unless you created other users)password-you-set-for-the-root-user
(unless you created other users)To find the instance connection name, go to the Cloud SQL instances page. Go to the overview page of your SQL instance and locate the Instance connection name.
driver:unix_socket=/cloudsql/your-instance-connection-name;dbname=your-database-name
.
where your instance connection name is your-project-name:us-east4:your-sql-instance-ID
.
For example, if your project name is cs4750, your SQL instance ID is db-demo, and the database name is guestbook,
host would be cs4750:us-east4:db-demo
DSN would be mysql:unix_socket=/cloudsql/cs4750:us-east4:db-demo;dbname=guestbook"
(where PDO driver is mysql).
Assuming that you have already set up your Cloud SQL. If you have not set up your Cloud SQL, please refer to DB setup on GCP.
Enter the IP address you got previously (this will allow your IP address to make a connection to the SQL instance), click Done and then click Save.
host would be your-cloud-instance-public-IP-address
DSN would be mysql:host=your-cloud-instance-public-IP-address;dbname=your-database-name
Assuming that you have already set up your PHP environment. If you have not set up your PHP environment, please refer to PHP deployment on GCP, PHP deployment on CS server, or PHP deployment using XAMPP.
Also assume that you have already set up your MySQL database using XAMPP. If you have not set up your database, please refer to DB setup using XAMPP.
your-host-name:port-number
your-database-name
root
(unless you create other users)password-you-set-for-the-root-user
(unless you create other users)localhost
SHOW VARIABLES WHERE Variable_name = 'port';
3306
.
driver:host=your-host-name:port-number;dbname=your-database-name
.
For example, assuming the database name is "guestbook", the DSN would be
mysql:host=localhost:3306;dbname=guestbook
(where PDO driver is mysql).
Assuming that you have already set up your PHP environment. If you have not set up your PHP environment, please refer to PHP deployment on GCP, PHP deployment on CS server, or PHP deployment using XAMPP.
Also assume that you have already set up your MySQL database on the CS department server. If you have not set up your database, please refer to DB setup using CS server.
mysql01.cs.virginia.edu
your-computingID
your-computingID
your-CS-mysql-password
driver:host=your-host-name:port-number;dbname=your-database-name
.
For example, the DSN would be
mysql:host=mysql01.cs.virginia.edu;dbname=your-computingID
(where PDO driver is mysql).
Note: MySQL database on the CS server uses a default port. Thus, no port number is needed here.
Released under the
CC-BY-NC-SA 4.0 license.