I use a lot of CLI PHP scripts to perform simple database operations on PHPMaker applications, usually running as cron jobs (or scheduled tasks in Windows). However, I want them using the same configuration from the web application, so I start my scripts by changing folders to the web application’s and loading configs and dependencies from there.
This is an working example in v2024:
namespace PHPMaker2024\MY_APPLICATION;
use Dflydev\DotAccessData\Data;
$WebRootPath = "C:/Inetpub/wwwroot/";
chdir($WebRootPath);
// Relative path
$RELATIVE_PATH = "";
// Autoload
include_once "vendor/autoload.php";
// Require files
require_once "src/constants.php";
require_once "src/config.php";
require_once "src/phpfn.php";
$ConfigData = new Data($CONFIG); // Ensure that $ConfigData is accessible by Global Codes
require_once "src/userfn.php";
$sql = "SELECT * FROM my_table";
$rs = ExecuteQuery($sql)->fetchAll();
I’m struggling to make it work in v2025. Of course, I updated the namespace to PHPMaker2025\MY_APPLICATION. Yet, I’m still getting this error:
Fatal error: Uncaught TypeError: PHPMaker2025\MY_APPLICATION\Conn(): Return value must be of type Doctrine\DBAL\Connection, null returned in C:\inetpub\wwwroot\src\phpfn.php:1985
What do I need to add into my script to make this work in v2025?