Webservice returning error

Asked

Viewed 25 times

2

My webservice is returning an error that I haven’t been able to resolve yet.

Follows the code:

`<?php
$dns = ‘mysql:host=localhost;dbname=diagnosys_db’;
$user = ‘user_name’;
$password = ‘user_password’;
try{
 $db = new PDO ($dns, $user, $pass);
}
catch( PDOException $e){
 $error = $e->getMessage();
 echo $error;
}
?>`

The error returned is as follows:

Parse error: syntax error, Unexpected ':' in /Storage/ssd4/128/11623128/public_html/db.php on line 2

  • 2

    You have declared a variable called $password, but when you are instantiating the PDO is using a variable called $pass, try replacing $pass with $password

  • 1

    Already analyzed the types of quotes you are using? in that reply you find a quick explanation about errors caused by quotation marks.

1 answer

1


Come on

You have declared a variable called $password, but when you are instantiating the PDO is using a variable called $pass, replace $pass with $password

Also adjust the quotation marks, follow below the code with the appropriate adjustments.

<?php
$dns      = 'mysql:host=localhost;dbname=banco-nome';
$user     = 'usuario-do-banco';
$password = 'senha';


try{
 $db = new PDO ($dns, $user, $password);

}
catch( PDOException $e){
 $error = $e->getMessage();
 echo $error;
}
?>
  • Even after this correction the error continues (although it was a great observation, thank you very much!)

  • Copy and paste the code I posted, and change only the information regarding the connection to the database.

Browser other questions tagged

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