 <p><strong>try this</strong> </p> <pre><code>try { $pdo = new PDO('mysql:host=localhost;dbname=yourdbname', 'dbuser' , 'password'); $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXECPTION); $pdo-&gt;exec('SET NAME "utf8"'); } catch (PDOException $e) { $error= 'error text'; include 'errorpage.php'; exit(); } $success = 'success'; include 'page.php'; </code></pre>