在session_start引发致命错误 [英] session_start Throws Fatal Error

查看:199
本文介绍了在session_start引发致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个小CMS为我的网站,并呼吁在session_start当我收到以下错误():

I'm currently working on a small CMS for my website and I'm getting following error when calling session_start() :

致命错误:异常未知中没有一个堆栈帧抛出在线0

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

我存储在$ _SESSION PDO的数据库连接,所以我需要在启动脚本后直接调用session_start()。
这里有一个片断:

I'm storing the PDO database connection in the $_SESSION, so I need to call session_start() directly after starting up the script. Here's a snippet :

function initDB($config){ //initalizes the database connection
try{
    @session_start();
}catch (Exception $e){

}
$dsn = 'mysql:dbname='.$config['db'].';host='.$config['host'];
$user = $config['usr'];
$password = $config['pw'];
try {
    $db = new PDO($dsn, $user, $password);
    $_SESSION['db'] = $db;
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

返回跟踪的误差@session_start(),所以我不能够SUS preSS的错误@甚至用一个try-catch。

Back traced the error to "@session_start()", so I'm not able to suspress the error with @ or even with a try-catch.

我希望你能帮助我。
非常感谢

I Hope you could help me. Thanks a lot

推荐答案

您不能存储资源(一个PDO对象实际上是一个资源)的会话。在重新初始化这个坏了,抛出一个异常外部你的PHP文件的范围。

You cannot store resources (a PDO object is actually a resource) in a session. On reinitialisation this is broken and throws an exception 'outside' the scope of your PHP file.

这篇关于在session_start引发致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆