在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.