Another Update! 2/2/13 Updated PHP to version 5.3 and it now gives me this message,
Fatal error: Uncaught exception 'PDOException' with message 'You cannot serialize or unserialize PDO instances' in [no active file]:0 Stack trace: #0 [internal function]: PDO->__sleep() #1 {main} thrown in [no active file] on line 0
However, I'm not using the serialize or unserialize function...
Update!
This works, but it is the incorrect and ugliest way of doing it. And I don't want to do it like this, but I figured that it might help
$db = new PDO("mysql:host=127.0.0.1;dbname=dbname;", "user", "pass"); public function login($user, $pass) { global $db; //stuff } ORIGINAL POST
I just switched over my project files to my web host (it works perfectly locally).
I'm getting this error, Fatal error: Exception thrown without a stack frame in Unknown on line 0.
It is oh so helpful. I am only including one file right now, it's a class with one function which counts the IDs of the entered username and password and then either returns true or false depending on what it found. (1 = true, anything but 1 = false).
I'm using PDO (mysql), and if I don't connect to my database I don't get the error but if I remove the session_start(); from the top of my document I also don't get the error. private $db;
public function __construct() { $this->db = new PDO("mysql:host=127.0.0.1;dbname=dbname;", "user", "pass"); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } And this is where I set the session,
if(isset($_POST["submit"])) { $errors = array(); if($user->login($_POST["user"], $_POST["pass"]) === false) { $errors[] = "Username or password is incorrect"; } if(empty($errors)) { $_SESSION["user"] = $_POST["user"]; header("Location: index.php"); } } I am not actually throwing an exception, anywhere. I don't know what this error means. I am running PHP Version 5.2.17
Here is my login function,
public function login($user, $pass) { $sql = $this->db->prepare("SELECT COUNT(`id`) FROM `users` WHERE `username` = :user AND `password` = :pass"); $sql->bindParam(":user", $user); $sql->bindParam(":pass", $pass); $sql->execute(); return ($sql->fetchColumn() == 1) ? true : false; } Index page (error occurs on every page that uses session_start, index page and login page)
session_start(); if(!isset($_SESSION["user"])) { header("Location: login.php"); }else { //begin HTML, no more php after this (except the closing bracket)