I am trying to connect the bank of an application in PHP in herokuapp
using ClearDB and I simply get a syntax error in line 6 of the code and I'm not sure exactly why. The application does not work, only if I put host , password and username directly, which is not possible since the application is in git
too.
Follow the code:
<?php
class Database {
private $url = parse_url(getenv("CLEARDB_DATABASE_URL"));
private $host = $url["host"];
private $db_name = substr($url["path"], 1);
private $username = $url["user"];
private $password = $url["pass"];
public $conn;
public function getConnection() {
$this->conn = null;
try {
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
} catch (PDOException $exception) {
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>