Si8
Si8

Reputation: 9225

PHP/SQL error which executing

<?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.

Upvotes: 0

Views: 77

Answers (1)

Francois Bourgeois
Francois Bourgeois

Reputation: 3690

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.

Upvotes: 3

Related Questions