php - Call function inside class -


i'm trying create simple class in php, i've got trouble method call.

<?php include('mysql.php');  class user {      var $sql;      function _construct(){         // sql connection          $this->sql = new mysql(<<hidden>>, <<hidden>>, <<hidden>>);     }      public function login($username, $password){         // todo     } } ?> 

at //todo section, want call $this->sql->select('users'), won't let me it. gives error , says sql non-object.

your "_construct" missing _ (you must have two), won't called. change :

public function __construct(){ 

it should work. remember make public.

if it's not called, $sql variable isn't initialized , non-object php.

also, may precise visibility of variable when declaring it, rather using deprecated var keyword :

private $sql; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -