Guest User

Untitled

a guest
Sep 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Object error: function query on a non-object
  2. <?php
  3.  
  4. class ManageDb{
  5. public $link;
  6.  
  7. function __construct() {
  8. include_once 'class_database.php';
  9. $conn = new database;
  10. $this->link = $conn->connect();
  11.  
  12. return $this->link;
  13. }
  14.  
  15. function getData($table_name, $id=null){
  16. if(isset($id)){
  17. $query = $this->link->query("SELECT * FROM $table_name WHERE id = '$id' ORDER BY id ASC");
  18. }else{
  19. **$query = $this->link->query("SELECT * FROM $table_name ORDER BY id ASC");**
  20. }
  21.  
  22. $rowCount = $query->rowCount();
  23. if ($rowCount >=1){
  24. $result = $query->fetchAll();
  25. }else{
  26. $result = 0;
  27. }
  28.  
  29. return $result;
  30. }
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37. ?>
  38.  
  39. <?php
  40. include_once '../config.php';
  41.  
  42. class database {
  43.  
  44. protected $db_conn;
  45. public $db_name = DB_NAME;
  46. public $db_host = DB_HOST;
  47. public $db_pass = DB_PASS;
  48. public $db_user = DB_USER;
  49.  
  50. function connect() {
  51. try {
  52. $this->db_conn = new PDO("mysql:host = $this->db_host;dbname=$this->db_name", $this->db_user, $this->db_pass);
  53. } catch (PDOException $e) {
  54. return $e->getMessage();
  55. }
  56. }
  57.  
  58. }
  59.  
  60. ?>
Add Comment
Please, Sign In to add comment