oop - php function not returning class object -


i have db class i've created several functions in return various values. 1 of functions returns (or supposed to) "user" class object represents logged in user application.

class user {    public $guid = '';    public $fname = '';    public $lname = '';     public function __construct() {}     public function print_option() {          return "<option value='$this->guid'>$this->name</option>";    } } 

in db class have following 2 functions:

public function get_user($uid) {     $sql = '';     $usr = new user();     $sql = "select guid, fname, lname ms.users guid=?";      if($sth = $this->conn->prepare($sql)) {         $sth->bind_param('s', $uid);         if($sth->execute()) {             $sth->bind_result($usr->guid, $usr->fname, $usr->lname);             $sth->fetch();             print_r($usr);  // prints out correctly             return $usr;         }         else {return null;}     }     else {return null;} }  public function get_practice_user_list($pguid) {     $ret = '';     $sql = "select user_guid ms.perm p_guid=?";     if($sth = $this->conn->prepare($sql)) {         $sth->bind_param('s', $pguid);         if($sth->execute()) {             $usr = new user();             $guid = '';              $sth->bind_result($guid);             while($sth->fetch()) {                 print_r($guid);  // prints guid correctly                 $usr = $this->get_user($guid);                 print_r($usr);   // prints nothing object null prints "error" 2 lines later.                 if($usr != null) $ret .= $usr->print_option();                 else print "error";             }              return $ret;         }         else {return null;}     }     else {return null;} } 

i'm not understanding why "user" object not returning in instance. others calls get_user function work fine , return user class object pertaining user.

tia

i guess guid may integer

    $sth->bind_param('s', $uid); 

bind_param's first param should 'i' not 's';

http://www.php.net/manual/en/mysqli-stmt.bind-param.php


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -