Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- <?php
- class Conexao {
- private $sql,$user,$pass,$lista;
- public function __construct($sql = 'mysql:host=localhost;dbname=teste',$user = 'root', $pass = '') {
- $this->sql = $sql;
- $this->user = $user;
- $this->pass = $pass;
- }
- public function Conecta(){
- try {
- new PDO($this->sql,$this->user,$this->pass);
- }catch(Exception $e) {
- var_dump($e);
- }
- }
- public function getList() {
- $this->lista = $this->Conecta()->prepare('SELECT * FROM outros');
- $this->lista->execute();
- $this->lista->fetchAll();
- }
- }
- $testando = new Conexao;
- $testando->Conecta();
- $testando->getList();
- public function Conecta(){
- try {
- return new PDO($this->sql,$this->user,$this->pass);
- }catch(Exception $e) {
- var_dump($e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement