Undefined variable: db

Rate this:
By ozyank (Contact - View My Woyano)
Published Mon 24 Sep 2007, 242 Views, 4 Comments

I am not sure what version of ezsql I am running. I inherited an application from someone else. I suspect that there is an incompatibility between earlier versions and PHP 5.2.0. After reading below, is there anything I can do to patch up the code I am using, which was modified extensively by the person who sent the application to me.

Dennis

Here is a snippet of the error message:

Notice: Undefined variable: db in D:DAdennismdb_search.php on line 32

Fatal error: Call to a member function get_results() on a non-object in D:DAdennismdb_search.php on line 32

At the beginning of the error page I get this:

dbh = @mysql_connect($dbhost,$dbuser,$dbpassword); if ( ! $this->dbh ) { $this->print_error("
    Error establishing a database connection!
  1. Are you sure you have the correct user/password?
  2. Are you sure that you have typed the correct hostname?
  3. Are you sure that the database server is running?

I am not an OO expert by any manys but I have a feeling that the variable "db" is not considered to be an object because of the way it is used in the get_results function. Here is the function directly from the class I am using.

        // Return the the query as a result set - see docs for more details
       
        function get_results($query=null, $output = OBJECT)
        {
           
            // Log how the function was called
            $this->func_call = "$db->get_results("$query", $output)";
           
            // If there is a query then perform it if not then use cached results..
            if ( $query )
            {
                $this->query($query);
            }       
   
            // Send back array of objects. Each row is an object       
            if ( $output == OBJECT )
            {
                return $this->last_result;
            }
            elseif ( $output == ARRAY_A || $output == ARRAY_N )
            {
                if ( $this->last_result )
                {
                    $i=0;
                    foreach( $this->last_result as $row )
                    {
                       
                        $new_array[$i] = get_object_vars($row);
                       
                        if ( $output == ARRAY_N )
                        {
                            $new_array[$i] = array_values($new_array[$i]);
                        }
   
                        $i++;
                    }
               
                    return $new_array;
                }
                else
                {
                    return null;   
                }
            }
        }
   



This Item
Category: Knowledge, Questions, General
Tags: ezsql questions
Share it
Link to this item:
Bookmark this item: RSS Feed

People who liked this item

    4 Comments

  1.  
    JV ~ 12 months ago
    0 votes thumbs up thumbs down
    In your function put global $db. For example....

    function my_func()
    {

    global $db;

    $db->query("insert blah into blah");

    }
    [ reply ]
    1.  
      ozyank ~ 12 months ago
      0 votes thumbs up thumbs down
      I am not sure where to put this. Do you mean in the function definition in the class? Would I have to put it in all the function definitions in the class?

      Thanks
      [ reply ]
      1.  
        ozyank ~ 11 months ago
        0 votes thumbs up thumbs down
        I never did get this to work. I read your comment and did not know where to put that. Please see the comment posed a month ago

        Thanks
        [ reply ]
      2.  
        ozyank ~ 12 months ago
        0 votes thumbs up thumbs down
        Hi...I still have this problem. Can anyone help?
        [ reply ]
        1.  
          22 votes thumbs up thumbs down
          This is my two cents...

             
          Hey you know AdGuy always gets the last word! ;)

        Please Login to Add Your Comment   ..or..  

        Replying to comment by