Fatal error: Exception thrown without a stack frame in Unknown on line 0

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. So I’m almost 100% sure that it has something to do with the session. I am running PHP Version 5.2.17.

[php]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);
}
[/php]
And this is where I set the session,
[php]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”);
}
}
[/php]
And this is my login function
[php]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;
	}[/php]

Update!

I’ve changed my mind, it must have something to do with the PDO connection or it being used in the construct.
If I do it like this, it works. But this is not how I want to do it. It is ugly and not the correct way of doing it.
[php]
$db = new PDO(“mysql:host=127.0.0.1;dbname=dbname;”, “user”, “pass”);

public function login($user, $pass) {
global $db;
//stuff
}
[/php]

I’m not familiar with this error. You should be wrapping your PDO calls in try/catch though

[php]
try {
$this->db = new PDO(“mysql:host=127.0.0.1;dbname=dbname;”, “user”, “pass”);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
exit($e->getMessage());
}
[/php]

To catch errors, right, it’s still outputting errors if there were any.

However, I’ve already tried wrapping it in try-catch and it gives me nothing. I’m starting to think it has something to do with the host or the php version installed on the server, since it works flawlessly locally.

Based on what I could find online, I think it has to do with something you are sending to the session. For example, from one page I read:

“a reference to an object which contained a reference to a PDO object. PDO objects cannot be serialized, and this exception was being thrown after the script had finished running”

http://e-mats.org/2008/07/fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/

If it is the session, then why does it work when I instantiate the PDO object outside of the class and then use global inside functions to use PDO?

And if you look at my code, I’m doing the normal, correct way. I’m storing a post value in the session, there is nothing wrong with that and I’m simply accessing it by using session start and the name of the session, simple stuff.

You would have to post the entire code otherwise I can’t really do anything.

That is, practically all the code but I’ll post it all in this post.
Index.php
[php]
session_start();

if(!isset($_SESSION[“user”])) {
header(“Location: login.php”);
}else {
include(“app/bootstrap.php”);
[/php]
Bootstrap.php
[php]
include(“class/class.user.php”);

$user = new User;
[/php]
Login.php
[php]
session_start();

if(isset($_SESSION[“user”])) {
header(“Location: index.php”);
}else {
include(“app/bootstrap.php”);

if(isset($_POST["submit"])) {
	$errors = array();
		
	if(empty($_POST["user"])) {
		$errors[] = "Please type in a username...";
	}
	if(empty($_POST["pass"])) {
		$errors[] = "Please type in a password...";
	}
	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");
	}
}

[/php]
User class
[php]
class User {

private $db;
	
public function __construct() {
	$this->db = new PDO("mysql:host=127.0.0.1;dbname=****;", "****", "****");
	$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
	
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;
}

}
[/php]

Good job, I forgot to edit out my password. Good thing it’s just a scrap account.

Yeah this is pretty strange. I tested out your code and couldn’t duplicate the error.

Which version of PHP are you using?

5.4.3

I guess it could be something with the version I’m using (5.2.2) seeing as how it works perfectly locally which is 5.4.7.

Host is updating to 5.3 on my account and if that doesn’t help then I’ll try some more debugging and if that doesn’t work then I guess I’ll have to settle by connecting outside of the class and then using a global variable :frowning:

Updated to 5.3.

It now gives me this error,
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

A bit more helpful, but still not very much. I don’t see where it thinks I’m serializing or unserializing

Error as been resolved!

You were right about the session. I renamed the session to “username” instead of “user” and then it started working. I called my user class for $user so I guess something went terribly wrong when I tried to name a session the same. Which is still terribly weird because $user is a variable and “user” is a string >_>

Do you have register_globals = On in your php.ini? I could see that confusing $user with the session variable ‘user’

It was on! I guess that was the issue this whole time. That explains why it worked when I ran it locally, I have register_globals off in XAMPP.

I also turned it off on my host now, not sure what it actually does (haven’t read up about it) but since it’s always been of on XAMPP it shouldn’t be an issue.

Sponsor our Newsletter | Privacy Policy | Terms of Service