Displaying a paginated list of forum topics using PHP PDO Can someone tell me if this code is safe? Can be sql-injected or something else hacked? Code get some rows from db and show in pages with pagination... if i can improve let me know and show me how, thanks.

$conn = new PDO('mysql:host=localhost;dbname=admin_admin', 'admin_admin', 'password');
     $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     $num_rows = $conn-&gt;query('SELECT COUNT(*) FROM a_topics')-&gt;fetchColumn(); 
     $pages = new Paginator($num_rows,25,array(25,50,100,250,'All'));
     $stmt = $conn-&gt;prepare('SELECT a_topics.pid, a_topics.title, a_topics.forum_id, b_forums.id, b_forums.name 
        FROM a_topics INNER JOIN b_forums ON a_topics.forum_id = b_forums.id
        ORDER BY a_topics.pid DESC LIMIT :start,:end');
     $stmt-&gt;bindParam(':start', $pages-&gt;limit_start, PDO::PARAM_INT);
     $stmt-&gt;bindParam(':end', $pages-&gt;limit_end, PDO::PARAM_INT);
     $stmt-&gt;execute();
     $result = $stmt-&gt;fetchAll();
     echo $pages-&gt;display_jump_menu().$pages-&gt;display_items_per_page();
     echo $pages-&gt;display_pages();
        foreach($result as $row) {
        echo "$row[0] - $row[1] - $row[2]";
     } catch(PDOException $e) {
     echo 'ERROR: ' . $e-&gt;getMessage();
     }
This code is safe from the SQL injection standpoint but it is likely prone to XSS because of the untreated output, and also to possibly leak the sensitive information due to the error message unconditionally spat out. 

Regarding other improvements I would suggest a more robust connection code and to avoid bindParam calls thanks to disabled emulation mode. 

The rewritten code would be 

include 'pdo.php';
$num_rows = $conn-&gt;query('SELECT COUNT(*) FROM a_topics')-&gt;fetchColumn(); 
$pages = new Paginator($num_rows,25,array(25,50,100,250,'All'));
$stmt = $conn-&gt;prepare('SELECT a_topics.pid, a_topics.title, a_topics.forum_id, b_forums.id, b_forums.name 
    FROM a_topics INNER JOIN b_forums ON a_topics.forum_id = b_forums.id
    ORDER BY a_topics.pid DESC LIMIT :start,:end');
$stmt-&gt;execute(['start' =&gt; $pages-&gt;limit_start, 'end' =&gt; $pages-&gt;limit_end]);
$result = $stmt-&gt;fetchAll();

echo $pages-&gt;display_jump_menu().$pages-&gt;display_items_per_page();
echo $pages-&gt;display_pages();
foreach($result as $row) {
    echo htmlspecialchars($row[0]),
         " - ", 
         htmlspecialchars($row[1]),
         " - ", 
         htmlspecialchars($row[2])";
}