Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Connecting to PlanetScale from PHP

These examples demonstrate how to connect a PHP application to a PlanetScale database using two different methods:

Follow the instructions below to find and insert your PlanetScale credentials.

Getting the credentials

  1. In the PlanetScale dashboard, select the database you want to connect to.
  2. Click "Branches" and select the branch you want to connect to.
  3. Click "Connect".
  4. Select "PHP" from the "Connect from" dropdown.
  5. If the password is blurred, click "New password".
  6. Copy the credentials. You won't be able to see the password again.

Connecting your database

  1. Replace the placeholders for HOSTNAME, DATABASE, USERNAME, and PASSWORD with the copied values. We encourage you to move these placeholder values into your .env file.
  2. To ensure a secure connection, you must fill in the SSL certificate path.
    • PDO option: This is the PDO::MYSQL_ATTR_SSL_CA value.
    • MySQLi option: This is the third parameter in the ssl_set() method.

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.

More resources

PlanetScale with PHP

PHP blog posts

Next steps