mysql - PHP - Constructing a class with PDO - Warning: Missing argument -


i have following select statement constructing user object:

$stmt = $conn->prepare("select user.user_id, user.user_name         user");     $stmt->execute();     $stmt->setfetchmode(pdo::fetch_class| pdo::fetch_props_late,'user');  

i have following class in separate file, included - require "user.php":

class user { private $user_id; private $user_name;  public function __construct($user_id, $user_name) {    $this->user_id = $user_id;    $this->user_name =$user_name; }     

i following warnings , notices -

warning: missing argument 1 user::__construct() notice: undefined variable: user_id 

it works fine turned on warnings etc tidying code.

i have looked @ other questions on here solutions don't seem , thought fresh pair of eyes help. thought had should have been passing array in setfetchmode() documentation states still seems cause issues.

what correct way create class in pdo?

if use arguments user constructor, need use third parameter in setfetchmode

public bool pdostatement::setfetchmode ( int $pdo::fetch_class , string $classname , array $ctorargs )

in case

$stmt->setfetchmode(pdo::fetch_class| pdo::fetch_props_late,'user', array('user_id','user_name'));     

or provide default values constructor.

see the reference.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -