Error "Parse error: syntax error, Unexpected end of file"

Asked

Viewed 2,641 times

-2

I’m having trouble connecting , where it presents 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

where line 27 does not exist only goes up 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;
}
  • you’re using this script ai to connect in a BD? you’ve heard of PDO?

  • I do not know if it was right but the script It is in PDO.,use to connect my local bank that works , but online presents this error.

  • 1
  • Which is line 26?

  • nor need these "if" ai, can take.

1 answer

1


Test something like that:

<?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 haven’t tried it, but I think it’s right.

  • 1

    worked , thanks. ,Renato Tavares

  • Mark the answer then as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.