"Parse error: syntax error, unexpected end of file" error [duplicate]

-2

I have a connection problem, where it displays the following error:

  

Parse error: syntax error, unexpected end of file in /var/www/html/showdospes.com.br/web/funcao/conecta.php on line 27

Since line 27 does not exist it only goes to 26, what is the correct way to close the script? aki the code:

<?php
function conecta( ){

  if(!defined("HOST")){
     define('HOST','localhost');
  }
  if(!defined("BD")){
     define('BD','bala');
  }
  if(!defined("USER")){
     define('USER','bombom');
  }
  if(!defined("PASS")){
     define('PASS','chocolate');
  }
try {
$conn = new PDO('mysql:hostname='.HOST.';dbname='.BD.';port=3306','.USER.','.PASS.');
}catch(Exception $e){
    echo $e -> getmessage();
}
return $conn;
}
    
asked by anonymous 18.03.2016 / 15:33

1 answer

1

Try something like this:

<?php

function conecta( ) {

  if(!defined("HOST")){
     define('HOST','localhost');
  }

  if(!defined("BD")){
     define('BD','bala');
  }

  if(!defined("USER")){
     define('USER','bombom');
  }

  if(!defined("PASS")){
     define('PASS','chocolate');
  }

    try {
        $conn = new PDO('mysql:hostname='.HOST.';dbname='.BD.';port=3306', USER, PASS);
    }catch(Exception $e) {
        echo $e->getmessage();
    }
    return $conn;
}

I just changed a few things in the DNS I did not test, but I think the correct one is so.

    
18.03.2016 / 15:43