Edit: As stated in comment section I removed try and catch statement to see the error and I was using the wrong database name. I was wondering am I suppose to remove the try and catch statement? Or just remove die() in catch and instead add some message such as echo $e->getMessage();?
In my php code whenever I write require "database.php" nothing works below that line. I am printing echo statement after require line, but it does not print. It's same if I have any code after that such as for loop or anything it won't print or go past the require line code. If I remove the require line everything works fine. What could be the reason for that?
My code:
<?php
//connecting to database
require "database.php";
echo 'after require code'; //this line won't print
// Errors on
error_reporting(E_ALL);
?>
database.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$servername;dbname=root", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die();
}
?>