You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coming Soon! Tutorial on getting php-wasm running in CloudFlare.
pdo_cfd1 requires PHP 8.1+
Connect & Configure
Simply pass the D1 object into the php-wasm constructor as cfd1 to enable pdo_cfd1 support. Once D1 is passed in, cfd1: will be available as a PDO driver.
exportasyncfunctiononRequest(event){constmainDb=event.env.mainDb;constphp=newPhpWorker({cfd1: { mainDb }});php.run(`<?php $pdo = new PDO('cfd1:mainDb');`);}
You can check phpinfo() to make sure that the D1 object is detected. CloudFlare D1 SQL module detected will display "yes" when the object has been passed in correctly:
PDO can be used with D1 just like any other SQL server:
exportasyncfunctiononRequest(event){constmainDb=event.env.mainDb;constphp=newPhpWorker({cfd1: { mainDb }});php.run(`<?php $pdo = new PDO('cfd1:main'); $select = $pdo->prepare( 'SELECT PageTitle, PageContent FROM WikiPages WHERE PageTitle = ?' ); $select->execute([$pageTitle]); $page = $select->fetchObject();`);}
Todo
Named replacement tokens - Currently only positional tokens are supported.
Error handling - Error handling is currently very rudimentary and does not propagage messages.