Custom file access database query to generate json (v2020)

I need to make some custom JSON api response in my project,

I have attempted to add the file to a no header/footer php in the project and be able to do a simple Query but have not been able to succeed, I can do a connection in PHP but will like to use the same as project. Query works and outputs JSON what is the right files to add ?This is what I have in custom.php:

<?php
namespace PHPMaker2020\ch22;
$RELATIVE_PATH ="./";

require_once $RELATIVE_PATH."vendor/autoload.php";
require_once $RELATIVE_PATH."phpfn.php";
require_once $RELATIVE_PATH."userfn.php";

$sql="SELECT json_build_object('type', 'FeatureCollection', 'features', json_agg(st_asgeojson(t.*)::json)) AS response
   FROM ( SELECT * from api_last) t;"; //outputs geojson
$geojsonstr =ExecuteScalar($sql);
echo $geojsonstr;
?>

errors:
Notice: Undefined variable: CONFIG in D:\xampp\htdocs\chub\phpfn.php on line 10Notice: Undefined variable: PurifierConfig in D:\xampp\htdocs\chub\phpfn.php on line 10499Warning: Use of undefined constant DB_FETCH_NUM - assumed ‘DB_FETCH_NUM’ (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\chub\phpfn.php on line 12623Warning: Use of undefined constant PROJECT_NAMESPACE - assumed ‘PROJECT_NAMESPACE’ (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\chub\phpfn.php on line 37Fatal error: Uncaught Exception: Undefined index: CONNECTION_INFO.DB in configuration. in D:\xampp\htdocs\chub\phpfn.php:39 Stack trace: #0 D:\xampp\htdocs\chub\phpfn.php(7710): PHPMaker2020\ch22\Config(‘CONNECTION_INFO…’) #1 D:\xampp\htdocs\chub\phpfn.php(7690): PHPMaker2020\ch22\Db(‘DB’) #2 D:\xampp\htdocs\chub\phpfn.php(12810): PHPMaker2020\ch22\Conn() #3 D:\xampp\htdocs\chub\phpfn.php(12623): PHPMaker2020\ch22\LoadRecordset(‘SELECT json_bui…’, NULL, Array) #4 D:\xampp\htdocs\chub_api.php(13): PHPMaker2020\ch22\ExecuteScalar(‘SELECT json_bui…’) #5 {main} thrown in D:\xampp\htdocs\chub\phpfn.php on line 39

mgqz wrote:

Notice: Undefined variable: CONFIG in D:\xampp\htdocs\chub\phpfn.php on line 10

As the error message suggested, you did not include the config file.

Hello, thanks for your reply, But I don’t have a config.php file or something similar, could you point out ?regards

I guess ewcfg.php needed but still errors…this is the code:

<?php namespace PHPMaker2020\ch22; $RELATIVE_PATH ="./";require_once $RELATIVE_PATH."vendor/autoload.php"; require_once $RELATIVE_PATH."ewcfg.php"; require_once $RELATIVE_PATH."phpfn.php"; require_once $RELATIVE_PATH."userfn.php";//include_once "ewcfg.php"; // <-- adjust the location to the actual path //include_once "phpfn.php"; // <-- adjust the location to the actual path $sql="SELECT json_build_object('type', 'FeatureCollection', 'features', json_agg(st_asgeojson(t.*)::json)) AS response FROM ( SELECT * from api_last) t;"; //outputs geojson $geojsonstr =ExecuteScalar($sql); echo $geojsonstr; ?>this is the erro:Fatal error: Uncaught Error: Call to undefined function PHPMaker2020\ch22\ADONewConnection() in D:\xampp\htdocs\chub\phpfn.php:7738 Stack trace: #0 D:\xampp\htdocs\chub\phpfn.php(7692): PHPMaker2020\ch22\ConnectDb(Array) #1 D:\xampp\htdocs\chub\phpfn.php(12810): PHPMaker2020\ch22\Conn() #2 D:\xampp\htdocs\chub\phpfn.php(12623): PHPMaker2020\ch22\LoadRecordset('SELECT json_bui...', NULL, Array) #3 D:\xampp\htdocs\chub\_api.php(15): PHPMaker2020\ch22\ExecuteScalar('SELECT json_bui...') #4 {main} thrown in D:\xampp\htdocs\chub\phpfn.php on line 7738