Session is stored in mysql database _ MySQL

Source: Internet
Author: User
Tags php example
The session is stored in the mysql database according to the session class in qq interconnection and the official php example.

 lifetime = get_cfg_var("session.gc_maxlifetime");  $this->dbHandle = $con;  if(!$con || !$sel)      return false;      return true; }function close(){    $this->gc($this->lifetime);return @mysql_close($this->dbHandle);}function read($id){   $rs = @mysql_query("select session_data data from ".self::db_table." where session_expires < ".time(),$this->dbHandle);    $row = @mysql_fetch_assoc($rs);return $row?$row['data']:'';}function write($id,$data){$newEXP = time()+ ini_get("session.gc_maxlifetime");   $sel = mysql_query("select * from ".self::db_table." where session_id= '".$id."'",$this->dbHandle);   if(mysql_affected_rows($this->dbHandle)){     $rs = @mysql_query("update ".self::db_table." set session_data = '".$data."', session_expires = '".$newEXP."' WHERE session_id = '".$id."'",$this->dbHandle);  if(@mysql_affected_rows($this->dbHandle))  return true;   }else{     $rs = @mysql_query("insert into ".self::db_table." (session_id,session_data,session_expires)values('".$id."','".$data."','".$newEXP."')",$this->dbHandle); if(@mysql_affected_rows($rs)) return true;   }   return false;}function destroy($id){@mysql_query("delete from ".self::db_table." where session_id = '".$id."'",$this->dbHandle);}function gc($lifetime){    @mysql_query("delete from ".self::db_table." where sessoin_expires > '".time()."'",$this->dbHandle);}}$session = new session();session_set_save_handler(array(&$session,'open'),array(&$session,'close'),array(&$session,'read'),array(&$session,'write'),array(&$session,'destroy'),array(&$session,'gc'));session_start();

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.