1
I’m trying to connect the database of a PHP application to herokuapp
using Cleardb and simply getting a syntax error on line 6 of the code and I don’t know exactly why. The application does not work, only if I put host, password and username directly, which is not possible because the application is in the git
also.
Follows 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;
}
}
?>
Which error appears?
– rray
This one "Parse error: syntax error, Unexpected '(', expecting ',' or ';' on line 6" ...
– Lucas de Albuquerque