Parse error: syntax error, unexpected

I just uploadd a site I amworking on, but get the following error:

Parse error: syntax error, unexpected ‘{’ in c:\domains\yoursite.nl\wwwroot\includes\connect.php on line 3

Not just in the normal templates but in the connection file as well, which look like this:


<?php
try
{
  $pdo = new PDO('mysql:host=localhost;dbname=db_name',
  '$user',
  '$pass');
}
catch (PDOException $e)
{
  echo 'Er is een database fout opgetreden.';
  exit();
}
?>
Offline it is working fine this way.

There’s nothing obvious there. I tried the code here on my localhost and it worked fine. Does it work OK if you just have the above code as a PHP file and call it up?

Off-the-wall suggestion … make the $pdo declaration as a single line. Perhaps there’s some config setting on your online server that doesn’t like that coding structure?

This is solved. On this particular server I needed to add the port to the PDO as well i.e.

  $pdo = new PDO('mysql:host=localhost;dbname=db_name;port=3351'   '$user',    '$pass');

That was all

This is strange, are you really sure this is how the problem is resolved?

+1, as that would not have solved a syntax error. You had to have something else going on too.

Try removing the single quotes around $user and $pass.

// from the PHP Manual
//
http://www.php.net/manual/en/pdo.connections.php



$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);


would it of mattered if it was EOL format i.e dos / unix