php5.5 Session_set_save_handler Connection Database issues

Source: Internet
Author: User
Long ago forgot where to copy, always use, but upgrade to PHP5.5 is not good with the warning
The server can not modify php.ini had to try to write with mysqli, but has not written out please expert advice!!
Thank you

function connect_db () {
$db _connect =
Mysql_connect ("host_name", "user_name", "password")
Or Die ("Could 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 AH ~ So change no more wrong!!!!!
Warning:session_start (): Cannot send session cookie-headers already sent by
warning:mysqli_select_db () expects exactly 2 parameters, 1 given in
Warning:mysqli_num_rows () expects parameter 1 to BES 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 would be a removed in the Future:use mysqli or PDO Instea D in

I'm sorry, the last deprecated didn't stick wrong.

Just waiting for you.
It's normal to make an error, just change it.
Not error and work is not normal, is the trouble

Error mysqli function because the default database connection Word cannot be
You can take $db as the first parameter of the function of error.

OK, thank you, 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.