php - PDO retriving ID -


i've been stuck @ awhile now, i'm trying create function in php retrives users id passing in users username funciton.

i'm using php's pdo , smacking me in face i'm getting following error:

"fatal error: call member function prepare() on non-object in /home/swinkidc/public_html/studentreach/core/user.php on line 8"

index.php -

include 'core/user.php'; $user->getuserid("alex"); 

core/user.php -

include('connect.php');  class user extends database{      public function getuserid($user){         $query = $_link->prepare('select `id` `users` `username` = :user');     }  }   

core/connect.php

    class database {          protected $_link;       public function __construct (){        $_link = new pdo("mysql:host=localhost; dbname=swinkidc_student", "swinkidc_student", "");     }   } 

thanks in advance!

you have access instance variables $this:

$this->_link = new pdo(...) // ... $this->_link->prepare(...) 

check docs more.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -