title: Undefined property: PDO::$connect_error
body: <p>I am trying to use <code>$dbc-&gt;connect_error</code> to check if any error occurs while trying to connect to my databease. I always get an error page saying:</p>
  
  <blockquote>
    <p>Notice: Undefined property: PDO::$connect_error in
    C:\xampp\htdocs\add_products_processing.php on line 7</p>
  </blockquote>
  
  <p>I am using Windows7 with XAMPP v3.2.2. The full code is shown below. I am sure that the username and the password are correct. Any advice?</p>
  
  <pre><code>&lt;?php
  
  $dsn = 'mysql:host=localhost;dbname=technoglance';
  $username = 'root';
  $password = 'password';
  $dbc = new PDO($dsn, $username, $password);
  if ($dbc-&gt;connect_error) {
      die("Connection failed: " . $dbc-&gt;connect_error);
  }
  
  $main_class =filter_input(INPUT_POST, 'main_class');
  $brand =filter_input(INPUT_POST, 'brand');
  $model =filter_input(INPUT_POST, 'model');
  $description =filter_input(INPUT_POST, 'description');
  $quantity =filter_input(INPUT_POST, 'quantity');
  $adding_date =filter_input(INPUT_POST, 'adding_date');
  $sell_price =filter_input(INPUT_POST, 'sell_price');
  $buying_price =filter_input(INPUT_POST, 'buying_price');
  
  if(!empty($main_class)){
               try{
              $query = "INSERT INTO products (main_class, brand, model, description, quantity, adding_date, sell_price, buying_price ) VALUES ('$main_class', '$brand', '$model', '$description', '$quantity', now(),'$sell_price', '$buying_price' );";
               // set the PDO error mode to exception
              $dbc-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              $dbc-&gt;exec($query);
               echo "Thank you. The record has been sent successfully.&lt;br&gt;&lt;br&gt;";
  
              }
              catch(PDOException $e){
                  echo $query . "&lt;br&gt;" . $e-&gt;getMessage()."&lt;br&gt;&lt;br&gt;";
  
              }
  }
  else{
      echo '&lt;h1&gt;Please use the contact form or don\'t leave an empty field!&lt;/h1&gt;';
  }
  
  ?&gt;
  </code></pre>