create functions in "main" that requires Objects

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a function query(String $query) in my DbConnector-class- goes  
like this:
function query($query) {
    $mysqlQuery = mysql_query($query, $this->link);
        $this->setError("Queryfeil: ".mysql_error());
        return false;
    return $mysqlQuery;
and the fetchArray($result)-function:
function fetchArray($result) {
    $output = mysql_fetch_array($result);
        $this->setError("Feil under henting fra databasen: ".mysql_error());
        return false;
    return $output;

then I have my "main"-page, where I try to make a function  
listSections()- like this:
function listSections(){
    $sections = $connector->query("select * from section");<-- line 27
    while($result= $connector->fetchArray($sections)){

when I try to run this function I get an error message:
Fatal error:  Call to a member function query() on a non-object in  
c:\wamp\www\cms\cmsadmin\section.php</b> on line 27

Is it possible to do what I'm thinking? To create a function who  
involves objects?

Re: create functions in "main" that requires Objects

Siv Hansen wrote:

Quoted text here. Click to load it

Hi Siv,

This seems like a scope problem to me. Where do you create the  
$connector object? If it's outside of the function listSections, it  
really is a scope problem.
If you created it in the same script where listSections resides (or in a  
script that includes the php file containing the definition of  
listSections, you could try:

function listSections(){
     global $connector;
     $sections = $connector->query("select * from section");
      while($result= $connector->fetchArray($sections)){



Site Timeline