prqlc/bindings/php/README.md
prql-php offers PHP bindings to prqlc crate through FFI.
It provides the Compiler class which contains compile, prqlToPL, plToRQ
and rqToSQL functions.
It's still at an early stage, and isn't published to Composer. Contributions are welcome.
The PHP FFI extension needs to be
enabled. Set ffi.enable in your php.ini configuration file to "true".
<?php
use Prql\Compiler\Compiler;
$prql = new Compiler();
$result = $prql->compile("from employees");
echo $result->output;
A way to establish a dev environment with PHP, the ext-ffi extension and Composer is to use a nix flake. After installing nix, enable experimental flakes feature:
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
Now you can spawn a shell from prql-php/:
nix shell github:loophp/nix-shell#env-php81 --impure
This will pull-in ext-ffi extension, because it's declared in composer.json.
There is a task build-php script that:
libprqlc_c,libprqlc_c.* into lib,prqlc.h into lib.task build-php
task test-php
./vendor/bin/phpcs --standard=PSR12 src tests