Stworzylem klase Session
i w niej metody przykladowe:
function Session
($gc_maxlifetime = "", $gc_probability = "", $gc_divisor = "",$_param=array()) {
$this->_handleErrors();
} else {
$this->_db['db_host'] = $_param['db_host'];
$this->_db['db_name'] = $_param['db_name'];
$this->_db['db_user'] = $_param['db_user'];
$this->_db['db_pass'] = $_param['db_pass'];
$this->_db['db_name2'] = "sessions";
}
// if $gc_maxlifetime is specified and is an integer number
if ($gc_maxlifetime != "" && is_integer($gc_maxlifetime)) {
// set the new value
@ini_set('session.gc_maxlifetime', $gc_maxlifetime);
}
// if $gc_probability is specified and is an integer number
if ($gc_probability != "" && is_integer($gc_probability)) {
// set the new value
@ini_set('session.gc_probability', $gc_probability);
}
// if $gc_divisor is specified and is an integer number
if ($gc_divisor != "" && is_integer($gc_divisor)) {
// set the new value
@ini_set('session.gc_divisor', $gc_divisor);
}
// get session lifetime
$this->sessionLifetime = ini_get("session.gc_maxlifetime");
// register the new handler
array(&$this, 'destroy'), );
register_shutdown_function('session_write_close');
// start the session
}
public function open($save_path, $session_name)
{
try{
$this->_dbh = new PDO('mysql:dbname='.$this->_db['db_name'].';host='.$this->_db['db_host'], $this->_db['db_user'], $this->_db['db_pass']);
}
catch(PDOException $e){
}
return true;
}
function read($session_id)
{
// reads session data associated with the session id
// but only if the HTTP_USER_AGENT is the same as the one who had previously written to this session
// and if session has not expired
foreach($this->_dbh->query("
SELECT
session_data
FROM
session_data
WHERE
session_id = '".$session_id."' AND
http_user_agent = '".$_SERVER["HTTP_USER_AGENT"]."' AND
session_expire > '".time()."' ") as $row);
// if anything was found
if ($row > 0) {
// return found data
return $row["session_data"];
}
NIe wiem czemu nie łączy mi z baza danych oraz czemu wypisuje ze nie rozpoznaje zapytania query
SQLSTATE[28000] [1045] Access denied for user 'ODBC'@'localhost' (using password: NO)
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\pobieralnia\user\include\class_session.php on line 166
Dane do mysql dobre bo wcześniej się łączyłem i łączyło mi przez PDO
skoro select w pdo wywoluje sie za pomoca query. ?
Ten post edytował tabbi 24.12.2010, 21:33:55