I'm trying to accomplish the same ends as outlined in this question but my application of that answer just does not work. I get blank white screens when attempting to perform any operation involving the database class.
This should be simple-- a user inputs a username and password into a form. If both are received by the controller, I query the database and compare a hash of the submitted password with the hash on file. The problem is, my page does not load once I start making database calls.
I have a controller and two classes. One class is a database connector, the other is an authentication module that depends on the database connector.
Database connector class:
class inquiry
{
protected $pdo;
// Set up the initial db connection
function __construct()
{
try
{
$this -> pdo = new PDO('mysql:host=127.0.0.1;dbname=mysqlserver','mydatabase','ffffffffffffffff');
$this -> pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this -> pdo -> setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
$this -> pdo -> setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$this -> pdo -> exec('set names "utf8"');
}
catch (PDOException $e)
{
echo $e -> getMessage();
}
}
}
Then, the authentication class:
class auth
{
private $username;
private $password;
private $db;
function __construct(inquiry $db)
{
$this -> db = $db;
}
function login($username, $password)
{
$this -> username = $username;
$this -> password = $password;
// Query database, get hashed password for username
$this -> db -> query('select password from users where username="bob";');
// Data needs to be fetched but PHP does not process anything past this point anyway
return true;
}
}
Then, in the controller:
require_once '../inc/class.inquiry.php';
require_once '../inc/class.auth.php';
if (isset($_POST['username']) && isset($_POST['password']))
{
// Probably doing something wrong here
$dbconnect = new inquiry();
$user = new auth($dbconnect);
$authorized = $user -> login($_POST['username'], $_POST['password']);
if ($authorized == true)
{
// Send user to index page
header('Location: index.php');
exit();
}
}
I've commented the sections where I think I'm going wrong, but I don't know what to actually do about it. Any tips would be appreciated!