W↓
All docs
🔑
Sign Up/Sign In
docs.turso.tech/sdk/php/
Public Link
Apr 6, 2025, 5:08:38 PM - complete - 5 kB
Starting URLs:
https://docs.turso.tech/sdk/php/
## Page: https://docs.turso.tech/sdk/php/ You can execute SQL queries against your existing database as follows: $createUsers = " CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER ); INSERT INTO users (name, age) VALUES ('Prof. Ir. Onno Widodo Purbo, M.Eng., Ph.D', 61); INSERT INTO users (name, age) VALUES ('Jim Geovedi', 41); INSERT INTO users (name, age) VALUES ('Nasirun', 59); "; $db->executeBatch($createUsers); $db->query("SELECT * FROM users")->fetchArray(); If you need to use placeholders for values, you can do that: $db->query("SELECT * FROM users WHERE id = ?", [1])->fetchArray(); --- ## Page: https://docs.turso.tech/sdk/php/quickstart You can execute SQL queries against your existing database as follows: $createUsers = " CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER ); INSERT INTO users (name, age) VALUES ('Prof. Ir. Onno Widodo Purbo, M.Eng., Ph.D', 61); INSERT INTO users (name, age) VALUES ('Jim Geovedi', 41); INSERT INTO users (name, age) VALUES ('Nasirun', 59); "; $db->executeBatch($createUsers); $db->query("SELECT * FROM users")->fetchArray(); If you need to use placeholders for values, you can do that: $db->query("SELECT * FROM users WHERE id = ?", [1])->fetchArray(); --- ## Page: https://docs.turso.tech/sdk/php/reference ## Installing Install the package to your project using composer: ## Initializing Make sure to add `use Libsql\Database` to access the `Database` object. ## In-Memory Databases libSQL supports connecting to in-memory databases for cases where you don’t require persistence: Or the simpler: ## Local Development You can work locally by passing a path as the first parameter. Or more explicitly: ## Remote Only You can use a remote only database by passing `url` and `authToken`. ## Embedded Replicas You can work with embedded replicas by passing a `path`, `url` and `authToken`. Embedded replicas can sync from the remote URL and delegate writes to the remote primary database: ### Sync Interval The `sync_interval` function allows you to set an interval for automatic synchronization of the database in the background: ### Manual Sync The `sync` function allows you to sync manually the local database with the remote counterpart: ### Read Your Own Writes The `readYourWrites` parameter configures the database connection to ensure that writes are immediately visible to subsequent read operations initiated by the same connection. This is **enabled by default**, and is particularly important in distributed systems to ensure consistency from the perspective of the writing process. You can disable this behavior by passing `false`: ## Simple Query You can acquire a connection from a database and call `query()` to invoke a SQL statement, as well as optional arguments: ## Prepared Statements You can prepare a cached statement using `prepare()`, bind parameters, and then query it: ## Placeholders libSQL supports the use of positional and named placeholders within SQL statements: ## Batch Transactions A batch consists of multiple SQL statements executed sequentially within an implicit transaction. The backend handles the transaction: success commits all changes, while any failure results in a full rollback with no modifications. ## Interactive Transactions Interactive transactions in SQLite ensure the consistency of a series of read and write operations within a transaction’s scope. These transactions give you control over when to commit or roll back changes, isolating them from other client activity. --- ## Page: https://docs.turso.tech/sdk/php/examples * * GitHub Copilot Write better code with AI * GitHub Advanced Security Find and fix vulnerabilities * Actions Automate any workflow * Codespaces Instant dev environments * Issues Plan and track work * Code Review Manage code changes * Discussions Collaborate outside of code * Code Search Find more, search less * Explore * Learning Pathways * Events & Webinars * Ebooks & Whitepapers * Customer Stories * Partners * Executive Insights * * GitHub Sponsors Fund open source developers * The ReadME Project GitHub community articles * * Enterprise platform AI-powered developer platform * Pricing ## Provide feedback ## Saved searches ## Use saved searches to filter your results more quickly Sign up