tags:

views:

38

answers:

2

I'd like to have access to $lastID when calling raw Is there a way to do this?

public static $lastID;  
public function raw($sql){

    if(!$result = mysql_query($sql)){
        throw new Exception("Could not perform query: " .mysql_error());
    }

    self::$lastID = mysql_insert_id();
    return($result);

}

Edit: it is a class member, it is static.

+1  A: 

you have to use inside raw

global $lastId;

Here's the related documentation http://ca.php.net/manual/en/language.variables.scope.php

Dominik
You can't declare variables using `var` when it is anything other than a class member. You also can't declare a function as public unless it is a method.
Yacoby
+2  A: 

The context isn't clear as but it looks as though $lastID is a class memeber, in which case to access it from within methods of that class you should use:

$this->lastID;

The other issue I can see in your code is that this line will not work

self::$lastID = mysql_insert_id();

As $lastID isn't static. Either declare $lastID as static (in which case its state will be shared across all objects of the class)

//change this
var $lastID; 

//to this to declare $lastID as static
static $lastID;

Or use $this-> rather than self::

$this->lastID = mysql_insert_id();
Yacoby
Okay, I declared it as static, but I'm still confused as how I can access it outside the class.
kylex
NM, figured it out:CLASSNAME::$lastID;
kylex