Php5.5session _ set_save_handler

Source: Internet
Author: User
Php5.5session _ set_save_handler I forgot to copy it from the database for a long time. it has been easy to use, but it is not easy to use when I upgrade PHP5.5.
If the server cannot modify PHP. ini, you have to try to write it using mysqli, but you cannot write it all the time. please advise !!
Thank you.

Function connect_db (){
$ Db_connect =
Mysql_connect ("host_name", "user_name", "password ")
Or die ("cocould not connect ");
Return $ db_connect;
}


Function open ($ save_path, $ session_name ){
Global $ db;
$ Db = connect_db ();
Return true;
}

Function close (){
Return true;
}

Function read ($ id ){
Global $ db;
Mysql_select_db ("db_name ");

$ Result = mysql_query ("SELECT *
FROM session_t
WHERE session_id = '{$ id }'");
If (mysql_num_rows ($ result) = 1 ){
$ Row = mysql_fetch_array ($ result );
Return $ row ['session _ data'];
} Else {
Return "";
}
}

Function write ($ id, $ sess_data ){
Global $ db;
Mysql_select_db ("db_name ");
$ Result = mysql_query ("SELECT *
FROM session_t
WHERE session_id = '{$ id }'");
If (mysql_num_rows ($ result) = 1 ){
$ Result = mysql_query ("UPDATE session_t
SET session_data = '{$ sess_data }'
WHERE session_id = '{$ id }'");
} Else {
$ Date = date ('Y-m-d H: I: s ');
$ Result = mysql_query ("insert into session_t
VALUES ('{$ id }',
'{$ Sess_data}', '{$ date }')");
}
Return true;
}

Function destroy ($ id ){
Global $ db;
Mysql_select_db ("db_name ");
$ Result = mysql_query ("DELETE from session_t
WHERE session_id = '{$ id }'");

Return true;

}

Function gc ($ maxlife_time ){
Return true;
}

Session_set_save_handler
("Open", "close", "read", "write", "destroy", "gc ");
?>


Reply to discussion (solution)

Change mysql _ to mysqli _

> Change mysql _ to mysqli _
Moderator ~ So it cannot be changed. there are more errors !!!!!
Warning: session_start (): Cannot send session cookie-headers already sent
Warning: mysqli_select_db () expects exactly 2 parameters, 1 given in
Warning: mysqli_num_rows () expects parameter 1 to be mysqli_result, null given in
Warning: mysqli_query () expects at least 2 parameters, 1 given in
Deprecated: mysql_connect (): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

Sorry, the last Deprecated has no sticking error.

Just waiting for you.
It is normal to make an error. just change it.
Not reporting errors and not working properly.

The error mysqli function cannot default the database connection word.
You can use $ db as the first parameter of the error function.

OK solved. thanks to the moderator.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.