par
Tracker » 14 oct. 2007, 11:31
Bon voilà le test, aucun problème chez moi
config: PHP 5.1.? / MySQL 5.?
Structure SQL
Code : Tout sélectionner
CREATE TABLE sessions
(
id varchar(32) not null primary key,
access int(10) not null,
dataobject blob not null
)
Code de test
<?php
class dummy
{
private $_server = array();
public function __construct()
{
$this->_server = $_SERVER;
}
}
$pdo = new PDO('mysql:host=localhost;dbname=test','root','');
if(!empty($_GET['action']) && $_GET['action']=='save')
{
$o = new dummy();
$pst = $pdo->prepare('replace sessions values (:id, :access, :dataobject)');
$pst->bindParam(':id', md5('test'));
$pst->bindParam(':access', mktime());
$pst->bindParam(':dataobject', serialize($o), PDO::PARAM_LOB);
if(!$pst->execute())
echo print_r($pdo->errorInfo());
else
echo 'ok';
}
else
{
$pst = $pdo->prepare('select * from sessions where id = :id');
$pst->bindParam(':id', md5('test'));
if($pst->execute())
{
if($tab = $pst->fetch(PDO::FETCH_ASSOC))
{
$o = unserialize($tab['dataobject']);
var_dump($o);
}
}
}
?>
Pour sauvegarder l'objet: http://...../test.php?action=save
Pour récuperer l'objet: http://...../test.php
Teste le code chez toi.
Bon voilà le test, aucun problème chez moi
config: PHP 5.1.? / MySQL 5.?
[i]Structure SQL[/i]
[code]
CREATE TABLE sessions
(
id varchar(32) not null primary key,
access int(10) not null,
dataobject blob not null
)
[/code]
[i]Code de test[/i]
[php]
<?php
class dummy
{
private $_server = array();
public function __construct()
{
$this->_server = $_SERVER;
}
}
$pdo = new PDO('mysql:host=localhost;dbname=test','root','');
if(!empty($_GET['action']) && $_GET['action']=='save')
{
$o = new dummy();
$pst = $pdo->prepare('replace sessions values (:id, :access, :dataobject)');
$pst->bindParam(':id', md5('test'));
$pst->bindParam(':access', mktime());
$pst->bindParam(':dataobject', serialize($o), PDO::PARAM_LOB);
if(!$pst->execute())
echo print_r($pdo->errorInfo());
else
echo 'ok';
}
else
{
$pst = $pdo->prepare('select * from sessions where id = :id');
$pst->bindParam(':id', md5('test'));
if($pst->execute())
{
if($tab = $pst->fetch(PDO::FETCH_ASSOC))
{
$o = unserialize($tab['dataobject']);
var_dump($o);
}
}
}
?>
[/php]
Pour sauvegarder l'objet: http://...../test.php?action=save
Pour récuperer l'objet: http://...../test.php
Teste le code chez toi.