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')");
}
}
?>
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')");
}
}
?>