$id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } $comments = []; while($row = $res->fetch(PDO::FETCH_ASSOC)) { $comments[] = $row; } return $comments; } function count_comments($id, $type) { global $pdo; $sql = 'SELECT count(*) AS count FROM comments WHERE ' . get_field_name($type) . ' = :id'; $values = array( ':id' => $id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } $comments = []; if($row = $res->fetch(PDO::FETCH_ASSOC)) { return $row['count']; } return 0; } function db_store_comment($nick, $email, $type, $id, $content) { global $pdo; $sql = 'INSERT INTO comments (ip, ' . get_field_name($type) . ', email, author, date, content) VALUES (:ip, :id, :email, :nick, :date, :content)'; $values = array ( ':ip' => $_SERVER['REMOTE_ADDR'], ':id' => $id, ':email' => $email, ':nick' => $nick, ':date' => time(), ':content' => $content, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function generate_comment_field($comments, $type, $id) { $emptytexts = array( 'dir' => 'Brak komentarzy do tego katalogu, możesz być pierwszy!', 'image' => 'Brak komentarzy do tego obrazka, możesz być pierwszy!', ); $headertexts = array( 'dir' => 'Komentarze do katalogu', 'image' => 'Komentarze do obrazka', ); if (count($comments) == 0) { $output = '