Login   Register  
PHP Classes
elePHPant
Icontem

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Radovan Janjic  >  PHP MySQL Session Handler  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP MySQL Session Handler
Save and retrieve PHP session data in MySQL
Author: By
Last change:
Date: 10 months ago
Size: 1,117 bytes
 

Contents

Class file image Download
<?php 

/** PHP MySQL Session Handler Example - Use same db connection for sessions and other coding ...
 *    
 *    PHP version required (4 >= 4.0.2, 5)
 *    
 */

include "MySQL_wrapper.class.php";
include 
"MySQL_Session_Handler.class.php";

define('MYSQL_HOST''localhost');
define('MYSQL_USERNAME''root');
define('MYSQL_PASSWORD''');
define('MYSQL_DATABASE''users');

$db = new MySQL_wrapper(MYSQL_HOSTMYSQL_USERNAMEMYSQL_PASSWORDMYSQL_DATABASE);

// Create object and start session
$GLOBALS['MYSQL_SESSION'] = new MySQL_Session_Handler($db'sessions');

//*
$_SESSION['asdf1'] = 'asdf';
$_SESSION['asdf2'] = 'asdf';
$_SESSION['asdf3'] = 'asdf';
$_SESSION['asdf4'] = 'asdf';
$_SESSION['asdf5'] = 'Array ( [asdf] => asdf [asdf1] => asdf [asdf2] => asdf [asdf3] => asdf [asdf4] => asdf [asdf5] => asdfa )';
//*/

echo '<pre>';

echo 
'Your session:'PHP_EOLprint_r($_SESSIONTRUE);

// Do queries and stuff with same connection ...
echo 'Your session id db:'PHP_EOLprint_r($db->fetchQueryToArray('SELECT * FROM `sessions`;'), TRUE);

// Hey, check your database ;-)