These examples demonstrate how to connect a PHP application to a PlanetScale database using two different methods:
- PDO — Connect using the PHP PDO class
- MySQLi — Connect using the PHP
mysqliextension
Follow the instructions below to find and insert your PlanetScale credentials.
- In the PlanetScale dashboard, select the database you want to connect to.
- Click "Branches" and select the branch you want to connect to.
- Click "Connect".
- Select "PHP" from the "Connect from" dropdown.
- If the password is blurred, click "New password".
- Copy the credentials. You won't be able to see the password again.
- Replace the placeholders for
HOSTNAME,DATABASE,USERNAME, andPASSWORDwith the copied values. We encourage you to move these placeholder values into your.envfile. - To ensure a secure connection, you must fill in the SSL certificate path.
- PDO option: This is the
PDO::MYSQL_ATTR_SSL_CAvalue. - MySQLi option: This is the third parameter in the
ssl_set()method.
- PDO option: This is the
This path depends on your system, so you need to paste in the appropriate value.
Here are some of the paths for commonly used systems:
MacOS / FreeBSD / OpenBSD
/etc/ssl/cert.pem
RedHat / Fedora / CentOS / Mageia / Vercel / Netlify
/etc/pki/tls/certs/ca-bundle.crt
Debian / Ubuntu / Gentoo / Arch / Slackware
/etc/ssl/certs/ca-certificates.crt
Alpine
/etc/ssl/cert.pem
OpenSUSE
/etc/ssl/ca-bundle.pem
You can find more configuration information in our Secure connections documentation. If you're on Windows, refer to the "Windows" section of that doc.
PlanetScale with PHP
- For more in depth instructions, check out the PHP quickstart or the sample PHP application.
- If you're looking for Laravel instructions, see the Laravel quickstart or the sample Laravel application.
- If you're looking for Symfony instructions, see the Symfony quickstart or the sample Symfony application.
PHP blog posts
- Build a Laravel application with a MySQL (PlanetScale) database
- Introduction to Laravel caching (w/ PlanetScale demo)
Next steps
- Learn more about the PlanetScale workflow.
- Learn how to branch your PlanetScale database for development.
- Learn how to ship schema changes to production with deploy requests.