Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ concurrency:
permissions: {}

jobs:
test-32-bit-php:
name: Reject 32-bit PHP
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- run: |
docker run --rm --platform linux/386 -v "$PWD:/repo:ro" -w /repo \
php:8.3-cli php packages/mysql-on-sqlite/tests/32-bit-php.php

test:
name: PHP ${{ matrix.php }} / SQLite ${{ matrix.sqlite }}
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ The monorepo packages are placed under the `packages` directory.
The WordPress plugin links the MySQL on SQLite package using a symlink. The build
script replaces the symlink with a copy of the package for release.

The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6,
MySQL syntax from version 5.7 onward, and requires SQLite 3.37.0 or newer
(with legacy mode down to 3.27.0).
The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6
and MySQL syntax from version 5.7 onward. The SQLite driver requires 64-bit PHP
and SQLite 3.37.0 or newer (with legacy mode down to 3.27.0).

## Commands
The codebase is written in PHP and Composer is used to manage the project.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ The monorepo packages are placed under the `packages` directory.
The WordPress plugin links the MySQL on SQLite package using a symlink. The build
script replaces the symlink with a copy of the package for release.

The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6,
MySQL syntax from version 5.7 onward, and requires SQLite 3.37.0 or newer
(with legacy mode down to 3.27.0).
The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6
and MySQL syntax from version 5.7 onward. The SQLite driver requires 64-bit PHP
and SQLite 3.37.0 or newer (with legacy mode down to 3.27.0).

## Quick start
The codebase is written in PHP and Composer is used to manage the project.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"require": {
"php": ">=7.2",
"php-64bit": "*",
"ext-pdo": "*",
"ext-pdo_sqlite": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mysql-on-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ composer run test -- --filter testName

## Requirements

- **PHP:** 7.2+
- **PHP:** 7.2+ (64-bit)
- **PHP extensions:** `pdo`, `pdo_sqlite`
- **SQLite:** 3.37.0+

Expand Down
1 change: 1 addition & 0 deletions packages/mysql-on-sqlite/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"require": {
"php": ">=7.2",
"php-64bit": "*",
"ext-pdo": "*",
"ext-pdo_sqlite": "*"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait WP_MySQL_On_SQLite_PDO_Compat {}
* It translates queries written in MySQL SQL dialect to an SQLite SQL dialect,
* maintains necessary metadata, and executes the translated queries in SQLite.
*
* The driver requires PDO with the SQLite driver, and the PCRE engine.
* The driver requires 64-bit PHP, PDO with the SQLite driver, and the PCRE engine.
*/
class WP_MySQL_On_SQLite extends PDO {
use WP_MySQL_On_SQLite_PDO_Compat;
Expand Down Expand Up @@ -135,9 +135,6 @@ class WP_MySQL_On_SQLite extends PDO {
'HIGH_NOT_PRECEDENCE' => 1 << 29,
'NO_ENGINE_SUBSTITUTION' => 1 << 30,
'PAD_CHAR_TO_FULL_LENGTH' => 1 << 31,

// Modes below require 64-bit PHP.
// TODO: Consider supporting these values on 32-bit PHP as well.
'TIME_TRUNCATE_FRACTIONAL' => 1 << 32,
);

Expand Down Expand Up @@ -810,6 +807,10 @@ public function __construct(
?string $password = null,
?array $options = null
) {
if ( PHP_INT_SIZE < 8 ) {
throw $this->new_driver_exception( 'The MySQL on SQLite driver requires 64-bit PHP.' );
}

$options = $options ?? array();

// PDO DSN can't include "\0" bytes; parsing stops at the first one.
Expand Down
24 changes: 24 additions & 0 deletions packages/mysql-on-sqlite/tests/32-bit-php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

require_once __DIR__ . '/../src/load.php';

if ( 4 !== PHP_INT_SIZE ) {
throw new RuntimeException( 'Run this test on 32-bit PHP.' );
}

// The opt-in for older SQLite versions must not bypass the PHP requirement.
define( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS', true );

$path = sys_get_temp_dir() . '/' . uniqid( 'mysql-on-sqlite-' ) . '.sqlite';
try {
new WP_MySQL_On_SQLite( 'mysql-on-sqlite:path=' . $path );
throw new RuntimeException( 'The driver accepted a connection on 32-bit PHP.' );
} catch ( WP_MySQL_On_SQLite_Exception $e ) {
if ( 'The MySQL on SQLite driver requires 64-bit PHP.' !== $e->getMessage() ) {
throw $e;
}
}

if ( file_exists( $path ) ) {
throw new RuntimeException( 'The driver created a database file on 32-bit PHP.' );
}
2 changes: 1 addition & 1 deletion packages/plugin-sqlite-database-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The archive is written to `build/plugin-sqlite-database-integration.zip`.
## Requirements

- **WordPress:** 6.4+
- **PHP:** 7.2+
- **PHP:** 7.2+ (64-bit)
- **PHP extensions:** `pdo`, `pdo_sqlite`
- **SQLite:** 3.37.0+

Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-sqlite-database-integration/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ function ( $result ) {
* When the plugin gets merged in wp-core, this is not to be ported.
*/
function sqlite_plugin_copy_db_file() {
// Bail early if the pdo_sqlite extension is not loaded.
if ( ! extension_loaded( 'pdo_sqlite' ) ) {
if ( PHP_INT_SIZE < 8 || ! extension_loaded( 'pdo_sqlite' ) ) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-sqlite-database-integration/admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ function sqlite_plugin_admin_notice() {
return;
}

if ( PHP_INT_SIZE < 8 ) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'The SQLite Integration plugin requires 64-bit PHP. Please switch to a 64-bit PHP installation before enabling SQLite.', 'sqlite-database-integration' )
);
return;
}

// Bail early if the pdo_sqlite extension is not loaded.
if ( ! extension_loaded( 'pdo_sqlite' ) ) {
printf(
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-sqlite-database-integration/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function sqlite_integration_admin_screen() {
);
?>
</p>
<?php elseif ( PHP_INT_SIZE < 8 ) : ?>
<div class="notice notice-error">
<p><?php esc_html_e( 'The SQLite Integration plugin requires 64-bit PHP. Please switch to a 64-bit PHP installation before enabling SQLite.', 'sqlite-database-integration' ); ?></p>
</div>
<?php elseif ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
<div class="notice notice-error">
<p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-sqlite-database-integration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"require": {
"php": ">=7.2",
"php-64bit": "*",
"ext-pdo": "*",
"ext-pdo_sqlite": "*"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The plugin replaces the default MySQL database layer with an SQLite-backed imple

**Important:** Enabling SQLite creates a separate, empty database; it does not migrate an existing site. If you enable it on a site that uses MySQL or MariaDB, WordPress will ask you to set up the site again. Disabling the plugin reconnects WordPress to the previous database with its data unchanged. Changes made while using SQLite are not transferred.

The plugin requires the PDO SQLite PHP extension and SQLite 3.37.0 or newer.
The plugin requires 64-bit PHP with the PDO SQLite extension and SQLite 3.37.0 or newer.

== Frequently Asked Questions ==

Expand Down Expand Up @@ -75,7 +75,7 @@ The value of `DB_PATH` must be an absolute path to the SQLite database file, or

= What does the plugin require? =

In addition to the WordPress and PHP versions listed above, the plugin requires the PDO SQLite PHP extension and SQLite 3.37.0 or newer. The setup screen also needs write access to the `wp-content` directory and will detect conflicting database drop-ins.
In addition to the WordPress and PHP versions listed above, the plugin requires 64-bit PHP with the PDO SQLite extension and SQLite 3.37.0 or newer. The setup screen also needs write access to the `wp-content` directory and will detect conflicting database drop-ins.

= Where can I submit my plugin feedback? =

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
return;
}

if ( PHP_INT_SIZE < 8 ) {
throw new RuntimeException( 'The SQLite Integration plugin requires 64-bit PHP.' );
}

if ( ! extension_loaded( 'pdo' ) ) {
wp_die(
new WP_Error(
Expand Down
Loading