As the title states I upgraded to php 8 from 7 and the class code no longer functions. I don't get any errors in the php-fpm/www-error.log to provide insight. I've tried to outline the code flow as follows. I hope someone can make sense of this and provide the changes needed.
What I uncovered is the class code receives the correct information to create the postgresql connection, but in php8 the $this->CONN is now empty.
index.php includes PicSql.inc.php
PiSql.inc.php includes DbSql.inc.php
DbSql.inc.php includes const.inc.php
const.inc.php contains the variables with the values to create the connection to postgresql
1. index.php
require("PicSql.inc.php");
$db = new PicSQL($DBName);
<p> Open Jobs <?=$db->getNumOpenJobs("Off Campus")?> </p>
2. PicSql.inc.php
require("DbSql.inc.php");
Class PicSQL extends DBSQL{
function PicSQL($DBName = ""){
$this->DBSQL($DBName);
}
function getNumOpenJobs($in, $workstudy=false, $neo=false){
...
$result = $this->select($sql);
...
}
}
3. DbSql.inc.php
require("const.inc.php");
//error_log dispalys all the correct values for the connecton from the const.inc.php include
error_log ("DbSql start const: " . $DBName . $DBUser .$DBPassword . $DBHost . $DBPort);
Class DBSQL{
function DBSQL($DBName){
global $DBHost,$DBUser,$DBPassword,$DBPort,$DBName;
$conn=pg_connect("host=$DBHost port=$DBPort user=$DBUser dbname=$DBName");
$this->CONN = $conn;
return true;
}
function select($sql=""){
if (empty($sql)) return false; //$sql is not empty here
if (empty($this->CONN)) return false; //$this->CONN is empty thus the code stops here
$conn = $this->CONN;
$results = pg_exec($conn,$sql) or die(pg_errormessage()."<br />");
if ((!$results) or (empty($results))){
return false;
}
$count = 0;
$data = array();
while ($row = pg_fetch_array($results)){
$data[$count] = $row;
$count++;
}
pg_freeresult($results);
return $data;
}
}