-1
public const $servername;
public const $username;
public const $password;
public const $dbname;

public function __construct() {
    $this->servername = "localhost";
    $this->username = "root";
    $this->password = "";
    $this->dbname = "vodkafairywe";
    $conn = new mysqli ($this->servername, $this->username, $this->password, $this->dbname);        
}

I got the following error;

Parse error: syntax error, unexpected '$servername' (T_VARIABLE) in C:\xampp\htdocs\sometest\db_conn.php on line 5

Line 5 for me is public const $servername;

I don't know whats wrong with it

JustBaron
  • 2,319
  • 7
  • 25
  • 37

2 Answers2

1

Constants dont have a $, and should BE IN CAPS.

public const SERVERNAME;

The error gives it away. Unexpected variable, not constant! :-P

If you are setting the value (and you are), then you shouldn't be using a constant, therefore, remove it to look like this:

public $servername;

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
0

Change public const $servername; to public $servername; Constants can not be used like variables and they are used for fixed values.

Eimsas
  • 492
  • 6
  • 21