PHPackages                             yerikmiller/cloudflare-d1-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yerikmiller/cloudflare-d1-php

ActiveLibrary[Database &amp; ORM](/categories/database)

yerikmiller/cloudflare-d1-php
=============================

A lightweight PHP client for Cloudflare D1 database

01PHP

Since Sep 25Pushed 7mo agoCompare

[ Source](https://github.com/Yerikmiller/cloudflare-d1-php)[ Packagist](https://packagist.org/packages/yerikmiller/cloudflare-d1-php)[ RSS](/packages/yerikmiller-cloudflare-d1-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cloudflare D1 PHP Client
========================

[](#cloudflare-d1-php-client)

A lightweight, framework-agnostic PHP client for interacting with Cloudflare D1 databases.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- cURL extension
- JSON extension
- A Cloudflare account with D1 database access

Installation
------------

[](#installation)

```
composer require yerikmiller/cloudflare-d1-php
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
require 'vendor/autoload.php';

use Cloudflare\D1\D1;

// Initialize the D1 client
D1::$accountId = 'your-account-id';
D1::$apiToken = 'your-api-token';
D1::$databaseId = 'your-database-id';

// Create a new D1 instance whatever you want
$d1 = new D1();
```

### Executing Queries

[](#executing-queries)

#### Fetching Data

[](#fetching-data)

```
// Get all rows from a table
$results = $d1->get('SELECT * FROM users');

// Get a single row
$user = $d1->first('SELECT * FROM users WHERE id = ?', [1]);

// Get a single value
$email = $d1->value('SELECT email FROM users WHERE id = ?', [1]);
```

#### Modifying Data

[](#modifying-data)

```
// Insert a new record
$affectedRows = $d1->execute(
    'INSERT INTO users (name, email) VALUES (?, ?)',
    ['John Doe', 'john@example.com']
);

// Update a record
$affectedRows = $d1->execute(
    'UPDATE users SET name = ? WHERE id = ?',
    ['John Updated', 1]
);

// Delete a record
$affectedRows = $d1->execute('DELETE FROM users WHERE id = ?', [1]);
```

#### Working with Results

[](#working-with-results)

```
// Get all users
$users = $d1->get('SELECT * FROM users');

foreach ($users as $user) {
    echo "User: {$user['name']} ({$user['email']})\n";
}

// Get the last insert ID
$id = $d1->execute(
    'INSERT INTO users (name, email) VALUES (?, ?)',
    ['New User', 'new@example.com']
);
$lastInsertId = $d1->value('SELECT last_insert_rowid()');
```

Error Handling
--------------

[](#error-handling)

```
try {
    $result = $d1->query('SELECT * FROM non_existent_table');
} catch (\Cloudflare\D1\D1Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance44

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b0830e368d7e201f795d06c98eb0932c92125fbca72e481be01a1f45cbc4123?d=identicon)[Yerikmiller](/maintainers/Yerikmiller)

---

Top Contributors

[![Yerikmiller](https://avatars.githubusercontent.com/u/42706176?v=4)](https://github.com/Yerikmiller "Yerikmiller (9 commits)")

### Embed Badge

![Health badge](/badges/yerikmiller-cloudflare-d1-php/health.svg)

```
[![Health](https://phpackages.com/badges/yerikmiller-cloudflare-d1-php/health.svg)](https://phpackages.com/packages/yerikmiller-cloudflare-d1-php)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
