1 (edited by Dante90 2008-09-11 13:06)

Topic: $this->

Hello... I wanto to ask you: what is this?

$this->

In the file mysql.php

    function query($sql, $unbuffered = false)
    {
        if (defined('PUN_SHOW_QUERIES'))
            $q_start = get_microtime();

        if ($unbuffered)
            $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
        else
            $this->query_result = @mysql_query($sql, $this->link_id);

        if ($this->query_result)
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));

            ++$this->num_queries;

            return $this->query_result;
        }
        else
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, 0);

            return false;
        }
    }

I am trying to make a page, but I have this error:

Notice: Undefined variable: this in c:\program files\easyphp1-8\www\prova_tabelle.php on line 64

And in that Line there is this php code:

60 function num_fields($query_id = 0)
61 {
62    global $db_type;
63    if (!$query_id)
64        $query_id = $this->query_result;
65        switch($db_type)
66        {
67            case 'mysql':
68                return ($query_id) ? @mysql_num_fields($query_id) : false;
69            break;
70            case 'mysqli':
71                return ($query_id) ? @mysqli_num_fields($query_id) : false;
72        }        
73 }

Dante

[img]http://img154.imageshack.us/img154/1262/wwzdx9.png[/img]
[img]http://img517.imageshack.us/img517/1542/dante90bu4.jpg[/img]
[img]http://img522.imageshack.us/img522/5276/eurohackersuserbarnb4.gif[/img]

Re: $this->

Use $db->num_fields(), but not DBLayer->num_fields().
$this points the DBLayer instance inside DBLayer class method.
See http://php.net/manual/en/language.oop.php for details.

Carpe diem