Forum Moderators: coopster
The exact code provided below works if implemented in a stand-alone script; but it will not work from the class.
Additionally, it will not print the row, nor output to the error log as requested in the " setHierarchies()" function. ("error_log" is on in the php.ini file.)
Can anyone give me some suggestions on why?
Thanks in advance!
Kevin J
<?php
class Hierarchies
{
/// Member Variables
protected $dbh=NULL;
protected $hierarchies=array();/// Member Methods
public function _construct( $incoming_dbh = NULL )
{
$this->setDbHandle( $incoming_dbh );
/// Set the list of hierarchies
$this->setHierarchies();
return $this;
}
protected function setDbHandle( $incoming_dbh )
{
$this->dbh=$incoming_dbh;
return TRUE;
}
public function getDbHandle() { return $this->dbh; }
protected function setHierarchies()
{
$sql="SELECT hierarchy_guid, hierarchy_name FROM hierarchies ORDER BY hierarchy_name ASC";
foreach ($this->getDbHandle()->query( $sql ) as $row)
{
print_r( $row );
error_log( print_r( $row ) );
$this->hierarchies[ $row['hierarchy_guid'] ] = $row['hierarchy_name'];
}
return TRUE;
}
public function getHierarchies() { return $this->hierarchies; }
}
?>
foreach ($this->getDbHandle()->query( $sql ) as $row)
Furthermore, your setHierarchies() method returns TRUE, regardless of what happens. You should either have it return the array, or a logic based boolean value (i.e. TRUE on success, FALSE on failure).
I personally think you're overthinking the concept. A single static method that takes the PDO handler as an argument, and produces the hierarchies array is all you need.