Guest User

Untitled

a guest
Aug 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. what is the error using OOPS with PDO
  2. class DB
  3. {
  4. public $dbh;
  5. private $qry;
  6.  
  7. public function __construct($user ='root',$pass = '')
  8. {
  9. try {
  10. $this->dbh = new PDO('mysql:host=localhost;dbname=parixan',$user,$pass);
  11. $this->dbh->exec("SET CHARACTER SET utf8");
  12. echo "connected";
  13. } catch(Exception $e){
  14. die("Unable to connect: " . $e->getMessage());
  15. }
  16. }
  17. }
  18.  
  19. class User
  20. {
  21. public $db;
  22. protected $_table ='tbl_user';
  23. public function __construct($dbh)
  24. {
  25. $this->db = $dbh;
  26. }
  27. public function getUserDetails($id) //line #10
  28. {
  29. $qry = "SELECT * FROM $this->_table WHERE id = :userID LIMIT 1";
  30. $stmt = $this->db->prepare($qry); //line #13
  31. $stmt->bindParam(':userID',$id,PDO::PARAM_INT);
  32. if ($stmt->execute()) {
  33. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  34. echo "<pre>";print_r($row);
  35. }
  36. }
  37.  
  38. }
  39.  
  40. }
  41.  
  42. include_once('class.user.php');
  43. include_once('class.db.php');
  44. $dbh = new DB();
  45. $obj_user = new User($dbh);
  46. $obj_user ->getUserDetails(1);
  47.  
  48. public function prepare($qry) {
  49. return $this->dbh->prepare($qry);
  50. }
Add Comment
Please, Sign In to add comment