PHP
Turso Quickstart (PHP)
Get started with Turso and PHP using the libSQL client in a few simple steps.
In this PHP quickstart we will learn how to:
- Retrieve database credentials
- Install the libSQL package
- Connect to a Turso database
- Execute a query using SQL
1
Retrieve database credentials
You will need an existing database to continue. If you don’t have one, create one.
Get the database URL:
turso db show --url <database-name>
Get the database authentication token:
turso db tokens create <database-name>
Assign credentials to the environment variables inside .env
.
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
You will want to store these as environment variables.
2
Install
First begin by adding libSQL to your project:
composer require darkterminal/libsql-client-php
3
Connect
Now connect to your local or remote database using the libSQL connector:
4
Execute
You can execute SQL queries against your existing database as follows:
Was this page helpful?