- Install libSQL with Composer
- Retrieve database credentials
- Connect to a Turso database
- Execute a query using SQL
- Sync changes to local database (optional)
Retrieve database credentials
You will need an existing database to continue. If you don’t have one, create
one.Get the database URL:Get the database authentication token:Assign credentials to the environment variables inside
.env.You will want to store these as environment variables.
Connect
Now connect to your local or remote database using the libSQL connector:
Or just:
Or just:
Embedded Replica
Embedded Replica
Local only
Local only
Local only
Local only
Remote only
Remote only
Execute
You can execute SQL queries against your existing database as follows:If you need to use placeholders for values, you can do that: