По непонятно мне причине выводит ошибку:
Fatal error: Uncaught Error: Call to a member function fetchAll() on boolean in /home/uhr/hr-tape.ru/index.php:43 Stack trace: #0 {main} thrown in /home/uhr/hr-tape.ru/index.php on line 43
<?
$config = json_decode(file_get_contents('config'));
$local = json_decode(file_get_contents($config->tpl.'/local.json'));
try {
$db = new PDO('mysql:host='.$config->db->host.';dbname='.$config->db->name, $config->db->user, $config->db->pass); //д Данные верные
}
catch(PDOException $e) {
exit(getTPL('errors/db_connect'));
}
function sendQuery($query,$vars) {
global $db;
try {
$prepare = $db->prepare($query); //object(PDOStatement)#6 (1) { ["queryString"]=> string(68) "SELECT `id`, `title`, `desc` FROM `posts` ORDER BY `id` DESC LIMIT 5" }
$execute = $prepare->execute($vars); //(выдает просто true) :c
return $execute;
}
catch(PDOException $e) {
exit(getTPL('errors/db_query'));
}
}
function getTpl($filename) {
global $config;
return file_get_contents($config->tpl.'/'.$filename.'.html');
}
$title = $local->title;
switch ($_GET['e']) {
default:
$title = $title->posts;
$query_count = 'SELECT count(*) FROM `posts`';
$query = 'SELECT `id`, `title`, `desc` FROM `posts` ';
$array = null;
$query .= 'ORDER BY `id` DESC LIMIT ';
if (is_numeric($_GET['offset'])) {
$query .= '?,';
$array = array();
array_push($array, $_GET['offset']);
}
$query .= 5;
$response = sendQuery($query,$array)->fetchAll();
$count = sendQuery($query_count, null)->fetchColumn();
if (!empty($response)) {
foreach ($response as $post) {
$posts.= str_replace(
array('$ID$','$TITLE$','$DESC$'),
array($post['id'],$post['title'],$post['desc']),
getTpl('posts_row'));
}
if (isset($_GET['scroll'])) exit ($posts);
else $content = str_replace(array('$POSTS$','$COUNT$'),array($posts,$count),getTpl('posts'));
}
else if (!isset($_GET['scroll'])) {
$content = getTpl('errors/posts_not_found');
}
break;
case 'post':
if (is_numeric($_GET['id'])) {
$query = 'SELECT `id`, `title`, `desc-full` FROM posts WHERE id = ? LIMIT 1';
$response = sendQuery($query,array($_GET['id']))->fetch(PDO::FETCH_BOTH);
if ($response) {
$title = $response['title'];
$content = str_replace(array('$TITLE$','$DESC-FULL$'),array($response['title'],$response['desc-full']),getTpl('post'));
} else {
$title = $local->error;
$content = getTpl('errors/post_not_found');
}
} else {
$title = $local->error;
$content = getTpl('errors/post_wrong_id');
}
break;
}
if (isset($content)) {
if (isset($_POST['ajax'])) {
exit (serialize(array($title,$content)));
} else {
exit(str_replace(
array('$TITLE$','$CONTENT$','$CDN$'),
array($title, $content, $config->cdn),
getTpl('main')));
}
}
?>
Подскажите пожалуйста в чем проблема и как можно исправить?