i have a connection file that is attached with contants.inc.php how i can connect it?
Connection file:
<?php
//Set the error reporting level
error_reporting(E_ALL);
ini_set(“display_errors”, 1);
//Start a PHP session
session_start();
//Include site constants
include_once "inc/constants.inc.php";
//Create a database object
try {
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
$db = new PDO($dsn, DB_USER, DB_PASS);
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
?>
contants.inc.php:
<?php
$url = parse_url(getenv('CLEARDB_DATABASE_URL'));
//Database credentials
define('DB_HOST', $url['localhost']);
define('DB_USER', $url['root']);
define('DB_PASS', $url['']);
define('DB_NAME', (substr($url['master'], 1)));
?>
What error is MySQL giving when you’re trying to connect to the database?
Notice: Undefined index: host in C:\wamp\www\pepmaster\inc\constants.inc.php on line 4
Notice: Undefined index: user in C:\wamp\www\pepmaster\inc\constants.inc.php on line 4
Notice: Undefined index: pass in C:\wamp\www\pepmaster\inc\constants.inc.php on line 4
It looks as though CLEARDB_DATABASE_URL is not set
Try this:
$url = parse_url(getenv('CLEARDB_DATABASE_URL'));
echo '<pre>';
var_dump( $url);
echo '</pre>';
die;
showing this error
array (size=1)
‘path’ => string ‘’ (length=0)
$url = parse_url(getenv(‘CLEARDB_DATABASE_URL’));
I had a quick search and looks as though the above statement should be set using Laravel and/or Heroku both of which I have no knowledge.
Try your setup again and pay particular attention to the database configuration.
system
Closed
June 12, 2016, 10:29pm
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.