0
<?php
$dbhost="host";
$dbusername="user";
$dbpassword="pass";
$dbname="db";

try {
  # MySQL with PDO_MYSQL
  $DBH = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  echo "Connected Successfully";
}
catch(PDOException $e) {
    echo $e->getMessage();
}

#  close the connection  
$DBH = null; 
?>

When running it in my server, i get the following error:

Parse error: parse error, unexpected '{' in /home/web/i/htdocs/search/pdo.php on line 7

I am trying to do a test to use PDO to save variable to a database and was advised PDO was the way to securely store variable to a database. Please let me know why I am receiving the error and how to resolve it.

2
  • 1
    Is this the full code your running on a separate PHP file - no other includes? Commented Mar 5, 2013 at 16:51
  • interfaithmedical.com/search/pdo.php Commented Mar 5, 2013 at 17:36

1 Answer 1

3

I've run your code and do not get a parse error. It looks all fine. Maybe you did not run the same as you posted here.

Sign up to request clarification or add additional context in comments.

2 Comments

I checked the PHP parser and everything is fine. Maybe it's the web server?
Is this now resolved as you have marked it as answered yet continue to post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.