Jump to content

whichiso

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by whichiso

  1. @mac_gyver I made the changes and they work great. I always thought something wasn't quite right in this code that I inherited with passing $DBName and then setting the global. --PicSql.inc.php require("DbSql.inc.php"); Class PicSQL extends DBSQL { function __construct($DBName = "") { //$this->DBSQL($DBName); parent::__construct($DBName); } --DbSql.inc.php require("const.inc.php"); Class DBSQL { //function DBSQL($DBName) function __construct($DBName) { //global $DBHost,$DBUser,$DBPassword,$DBPort,$DBName; //$DBName removed so call-time parameter $DBName is used global $DBHost,$DBUser,$DBPassword,$DBPort; $conn=pg_connect("host=$DBHost port=$DBPort user=$DBUser dbname=$DBName"); $this->CONN = $conn; return true; }
  2. @mac_gyverSince the issue with the $DBName was brought up, is there a better way to code this. Also should function DBSQL be renamed to function __contruct like function PicSQL was? require("DbSql.inc.php"); Class PicSQL extends DBSQL{ function __construct($DBName = "") { $this->DBSQL($DBName); } require("const.inc.php"); //defines $DBName variable 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; }
  3. That did it. Changing PicSQL to __construct and the code all behaved as in php7. Is there any possible clarification beyond what you mentioned?
  4. Also I put an error_log statement inside the function PicSQL and it does not execute. Class PicSQL extends DBSQL{ function PicSQL($DBName = "") { error_log("picsql dbsql call"); $this->DBSQL($DBName); } The server with php7 and the same class code, the error_log statement does execute from inside the function PicSQL($DBName = ""). Thus the class syntax is no longer working in php8. The same is with the function DBSQL($DBName). the error_log statement in front of the connection statement lists of the values for the connection variables. Class DBSQL{ function DBSQL($DBName)
  5. does the database have a password set for the connection? No is this the exact code that has previously worked? Yes do other types of php errors get logged? Yes The function DBSQL($DBName) in DbSql.inc.php is no longer being accessed, for the error_log statement, which I put inside as the first statement, is not showing in the log.
  6. 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; } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.