phpsqlitepdo

PHP Sqlite PDO latest version


I want to use the latest version of sqlite (3.49.0 from this writing) in PHP.

I'm using docker and for latest docker image cli version (php:8.2-cli) sqlite3 shows the following version:

$ docker compose run --rm php php -r "echo SQLite3::version()['versionString'] . PHP_EOL;"
3.40.1

After I manually install the latest sqlite3 version via the following

RUN curl -L https://www.sqlite.org/2025/sqlite-autoconf-3490000.tar.gz | tar xz && \
    cd sqlite-autoconf-3490000 && \
    ./configure --prefix=/usr/local && \
    make && make install && \
    cd .. && rm -rf sqlite-*

I can see that sqlite3 is at latest version

$ docker compose run --rm php sqlite3 --version
3.49.0 2025-02-06

but the PDO version is still at older version:

$ docker compose run --rm php php -r "echo SQLite3::version()['versionString'] . PHP_EOL;"
3.40.1

My question is, how do I update PDO to use the latest sqlite3 version?

--- edit with answer ---

Dockerfile with custom PDO:

FROM php:8.2-cli

RUN apt-get update && apt-get install -y \
    wget \
    build-essential \
    libxml2-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

RUN curl -L https://www.sqlite.org/2025/sqlite-autoconf-3490000.tar.gz | tar xz && \
    cd sqlite-autoconf-3490000 && \
    ./configure && \
    make && make install && \
    cd .. && rm -rf sqlite-*

RUN docker-php-ext-disable pdo_sqlite

RUN docker-php-source extract \
    && cd /usr/src/php \
    && ./configure \
        --with-pdo-sqlite=/usr/local \
    && make -j$(nproc) \
    && make install \
    && docker-php-source delete

RUN docker-php-ext-configure pdo_sqlite --with-pdo-sqlite=/usr/local \
    && docker-php-ext-install pdo_sqlite

Solution

  • My question is, how do I update PDO to use the latest sqlite3 version?

    You have to update the PDO extension, and specifically the sqlite3 driver extension of PDO with the updated libraries as well.

    PDO is part of core, you can find the source code here: https://github.com/php/php-src/?tab=readme-ov-file#building-php-source-code

    SQLite3 is already mentioned in the prerequisites before make.