I have a connection.php class, which is just here for the connection string to my MySQL database using the PDO object.
Then, I call the connection.php class in a query.php page, but when I try to get the PDO object from connection.php, I get an error "Expression is not allowed as field default value". (btw, my IDE is phpstorm)
Here is connection.php
class connection
{
private $host = "XXX";
private $db = "XXX";
private $login = "XXX";
private $password = "XXX";
public function conn()
{
try
{
$bddconn = new PDO('mysql:host='.$this->host.';dbname='.$this->db, $this->login, $this->password);
}
catch(PDOException $e)
{
echo "Connection failed " . $e->getMessage();
}
return $bddconn;
}
}
And here is query.php
class query extends connection
{
public $bdd = parent::conn();
public function checkUser($login, $password)
{
$query = 'SELECT login, password FROM user WHERE login = ? AND password = ?;';
$req = $this->bdd->prepare($query);
return $req->execute(array($login, $password));
}
}
However, at this point the IDE displays the error "Expression is not allowed as field default value" on query.php line 2 (public $bdd = parent::conn();)
What is the problem on my code?