The following code, using the same pattern I've used before without this problem, is generating this error:
Fatal error: Call to a member function select() on a non-object in C:\wamp\www********\children.php on line 43
I can't seem to see the problem, and am hoping some fresh eyes can locate what stupidity I've done here. :rolleyes: (I've flagged the offending line #43 with a comment.)
<?php
class Children
{
// ATTRIBUTES //
var $db; // Mysql() object
// METHODS //
/*
void Children(obj $db)
constructor
*/
function Chidren($db)
{
if(is_object($db))
{
$this->db = $db;
}
else
{
user_error("Children::Children(): invalid DB object parameter");
}
}
/*
array getChildren(int $id)
returns array of "children" for supplied user id
*/
function getChildren($id)
{
$id = (int) $id;
$sql = "
SELECT
`customers_id`,
`customers_firstname`,
`customers_lastname`,
`customers_status`
FROM `customers`
WHERE `parent_id` = $id AND `account_type` = 2
ORDER BY `customers_lastname`, `customers_firstname`
";
$result = $this->db->select($sql); // <----------<<< THIS IS LINE 43
if($result === FALSE)
{
user_error("Children::getChildren(): ".$this->db->error);
return(FALSE);
}
elseif($result === 0)
{
return(array());
}
return($result->getArray());
}
}
// test
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once $_SERVER['DOCUMENT_ROOT'].'/classes/Mysql.class.php';
$db = new Mysql('mysql.ini');
$connx = $db->connect() or die($db->error);
$test = new Children($db);
$children = $test->getChildren(1383);
printf("<pre>%s</pre>\n", print_r($children, 1));
If you need to see the Mysql class, let me know. But like I said, I've used it this way a number of times without a problem, so I suspect it's just something stupid I've done within this class.