PHP是否存在这些类型的连接的特定会话

I need a session object for these type of connections mine seems not to be working with my current connection, is there a specific one of will it work with my connection. Here is the code:

Connection:

$conn = mysql_connect(db_server, db_user, db_pass);

if (!$conn)
die("Could not connect: " . mysql_error());

mysql_select_db(db_name, $conn);

Here is my current session object but it does not seem to work with this type of connection. Here is the code:

Session:

session_start();

//Global User Object Var
//loggedInUser can be used globally if constructed
if(isset($_SESSION['userSession']) && is_object($_SESSION['userSession']))
{
    $loggedInUser = $_SESSION['userSession'];
}

When I try to log in as $loggedInUser = $_SESSION['userSession']; the session does not start. Is there another session that needs to be build or why is this session not working with my current connection?

Storing an object in $_SESSION causes it to be serialised and deserialised. For regular objects this works provided the class definition is included before the object is deserialised.

However, mysql maintains the state of the database connection, which won't survive the process. Each new page requires a new connection to be built, so you can't store a mysql connection in $_SESSION.

Your solution is to store the database connection parameters and recreate the connection at the top of every page.