Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Fatal error: Uncaught Error: Call to a member function prepare() on null in /opt/lampp/htdocs/site/config/config.class.php:32 Stack trace: #0 /opt/lampp/htdocs/site/config/config.class.php(43): Conexao->getList() #1 {main} thrown in /opt/lampp/htdocs/site/config/config.class.php on line 32
  2.  
  3. <?php
  4.  
  5. class Conexao {
  6.  
  7. private $sql,$user,$pass,$lista;
  8.  
  9. public function __construct($sql = 'mysql:host=localhost;dbname=teste',$user = 'root', $pass = '') {
  10.  
  11. $this->sql = $sql;
  12. $this->user = $user;
  13. $this->pass = $pass;
  14.  
  15. }
  16.  
  17. public function Conecta(){
  18.  
  19. try {
  20.  
  21. new PDO($this->sql,$this->user,$this->pass);
  22.  
  23. }catch(Exception $e) {
  24.  
  25. var_dump($e);
  26.  
  27. }
  28.  
  29. }
  30.  
  31. public function getList() {
  32.  
  33. $this->lista = $this->Conecta()->prepare('SELECT * FROM outros');
  34. $this->lista->execute();
  35. $this->lista->fetchAll();
  36.  
  37. }
  38.  
  39. }
  40.  
  41.  
  42. $testando = new Conexao;
  43. $testando->Conecta();
  44. $testando->getList();
  45.  
  46. public function Conecta(){
  47.  
  48. try {
  49.  
  50. return new PDO($this->sql,$this->user,$this->pass);
  51.  
  52. }catch(Exception $e) {
  53. var_dump($e);
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement