Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- what is the error using OOPS with PDO
- class DB
- {
- public $dbh;
- private $qry;
- public function __construct($user ='root',$pass = '')
- {
- try {
- $this->dbh = new PDO('mysql:host=localhost;dbname=parixan',$user,$pass);
- $this->dbh->exec("SET CHARACTER SET utf8");
- echo "connected";
- } catch(Exception $e){
- die("Unable to connect: " . $e->getMessage());
- }
- }
- }
- class User
- {
- public $db;
- protected $_table ='tbl_user';
- public function __construct($dbh)
- {
- $this->db = $dbh;
- }
- public function getUserDetails($id) //line #10
- {
- $qry = "SELECT * FROM $this->_table WHERE id = :userID LIMIT 1";
- $stmt = $this->db->prepare($qry); //line #13
- $stmt->bindParam(':userID',$id,PDO::PARAM_INT);
- if ($stmt->execute()) {
- while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- echo "<pre>";print_r($row);
- }
- }
- }
- }
- include_once('class.user.php');
- include_once('class.db.php');
- $dbh = new DB();
- $obj_user = new User($dbh);
- $obj_user ->getUserDetails(1);
- public function prepare($qry) {
- return $this->dbh->prepare($qry);
- }
Add Comment
Please, Sign In to add comment