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