Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Call to member function fetchALL() - PDO
KrissTo
post
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 25.05.2016

Ostrzeżenie: (0%)
-----


Witam,
mam otóż pewien problem, kod czatu, który na localu działa bez zarzutów a po wgraniu na serwer wywala błąd, z którym nie bardzo wiemy co zrobić :/
Zarówno na localu jak i serwerze mamy PHP 5.6 a na serwerze wywala poniższy błąd:

Cytat
Fatal error: Call to a member function fetchAll() on boolean in


A oto poniższy kod: może ktoś będzie wiedział co jest przyczyną lub naprowadzi na problem:

Kod
<?php
session_start();
$a = new App;
    $a->newUser('xantiv');
    $id = $a->getUid('xantiv');
    foreach ($id as $r) {
        $sid = $r['u_id'];
    }
    $_SESSION['user'] = $sid;
    $_SESSION['do_kogo'] = $sid;

class Core {
    
        protected $db, $result, $prepared;
        private $rows;

        public function __construct () {
            $this->db = new PDO("mysql:host=localhost;dbname=dbb", "user", "pass");
        }

        
        public function query ($sql) {
            $this->result = $this->db->query($sql);
        }

        
        public function rows () {
            $this->rows = $this->result->fetchAll(PDO::FETCH_ASSOC);
            return $this->rows;
        }

    }
class App extends Core {

        public function getUid ($username) {
            $this->query("SELECT u_id FROM Users WHERE Username='$username' LIMIT 1");
            return $this->rows();
        }

        public function newUser ($username) {
            $this->query("INSERT INTO Users (Username) VALUES ('$username')");
        }
        
        // pobieranie wiadomosci z bazy
        public function fetchMessages () {
            $this->query("
                SELECT
                        `Messages`.`Message`,
                        `users`.`username`,
                        `users`.`u_id`    
                FROM    `Messages`
                JOIN     `users`
                ON         `Messages`.`u_id` = `users`.`u_id`
                ORDER BY `Messages`.`time`
                ASC
            ");
            return $this->rows();
        }
        
        
        public function insertMessage ($u_id, $message,$do_kogo) {
            $this->query("INSERT INTO Messages (u_id, Message, time,do_kogo)
                VALUES ($u_id, '$message', NOW(),'$do_kogo')");
        }

    }
?>
Go to the top of the page
+Quote Post
com
post
Post #2





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


masz na sztywno wpisane dane do bazy, pewnie są blednę, bo $this->db zwraca Ci boola (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #3





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Masz blad bazy.
Wyswietl go sobie a dowiesz sie w czym problem.

A problem pewnie lezy w nazwach tabel. Raz masz Users a raz users, i zapewne tylko jedna wersja jest prawdziwa (IMG:style_emoticons/default/wink.gif) A ze lokalnie pewnie pracujesz na windows to dla windows wielkosc liter nie ma znaczenia, zas na normalnym systemie wielkosc liter ma znaczenie (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
KrissTo
post
Post #4





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 25.05.2016

Ostrzeżenie: (0%)
-----


Cytat(nospor @ 25.05.2016, 15:00:26 ) *
Masz blad bazy.
Wyswietl go sobie a dowiesz sie w czym problem.

A problem pewnie lezy w nazwach tabel. Raz masz Users a raz users, i zapewne tylko jedna wersja jest prawdziwa (IMG:style_emoticons/default/wink.gif) A ze lokalnie pewnie pracujesz na windows to dla windows wielkosc liter nie ma znaczenia, zas na normalnym systemie wielkosc liter ma znaczenie (IMG:style_emoticons/default/wink.gif)


Oo widzisz, dzięki Ci bardzo, nie sądziłem że to przez to ale już na przyszłość będę pamiętał. Dzięki za pomoc (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #5





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Bardziej pamietaj o tym, by wyswietlac bledy zapytan, to zawsze bedziesz widzial w czym problem od razu.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 03:45