Best practice-creating a good PDO connection I have this code for updating time of login failure.The other parts of the code are stripped and simplified because my question is related to PDO.Here I have a db_config.php and a function to update time.I want to know is this a best   practice for PDO connection and accessing variables in a function?

db_config.php

&lt;?php
try 
{
  $dbh =  new PDO('mysql:host=localhost;dbname=mark1',dbusername,dbpassword);
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} 
catch(PDOException $e) 
{
  echo 'ERROR: ' . $e-&gt;getMessage();
} 
?&gt;


Code for update time function.

&lt;?php
require('db_config.php')

$login = strtolower($_POST['login']);

$sql = "SELECT * FROM members WHERE email=:email_db";
$result = $dbh-&gt;prepare($sql);
$result-&gt;bindParam(':email_db', $login);
$result-&gt;execute();
$row = $result-&gt;fetch(PDO::FETCH_ASSOC);

if($row &gt; 0)
{
  if($row['user_failed_logins'] == 5 &amp;&amp; $row['user_last_failed_login'] &gt; (time() - 60) )// Blocks login attempt for 1 min.
  {
    UpdateLoginFailTime($login,$dbh);
  }
  else
  {
    //Do something...
  }

function($login,$dbh)
{
  $time = time();
  $sql_update_login_fail_fileds = "UPDATE members SET user_last_failed_login = :user_last_failed_login WHERE email = :email";
  $result_update_login_fail_fileds = $dbh-&gt;prepare($sql_update_login_fail_fileds);
  $result_update_login_fail_fileds-&gt;bindParam(':user_last_failed_login', $time);
  $result_update_login_fail_fileds-&gt;bindParam(':email', $login);
  $result_update_login_fail_fileds-&gt;execute();

  echo "You have been blocked.Please try login after 1 minute"));
}
?&gt;
Please, never use procedural code-style with object oriented libraries.
For php5+: this is not good code-style, please, see article about Object Oriented Programming; for php5-: this is tolerable variant(but I don't remember if php4 has had PDO).

After learning something about OOP, try to read something about MVC(Model-View-Controller) and Design Patterns(ex.: "GOF: Design Patterns")

P.S. Sorry if it seems roughly for you. But if you want to write best code - it's the only way.