Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celsowm/d21a6915090e919a9a576b80ce3007e0 to your computer and use it in GitHub Desktop.
Save celsowm/d21a6915090e919a9a576b80ce3007e0 to your computer and use it in GitHub Desktop.
<?php
//table example: https://gist.github.com/celsowm/82cace3ae81fdaf653a3e944007892bc
include 'conexao.php';
class Log implements \Serializable {
public $id;
public $dados;
public function serialize() {
return serialize((array) $this);
}
public function unserialize($serialized): void {
foreach (unserialize($serialized) as $p => $v) {
$this->{$p} = $v;
}
}
}
/*$log = new Log();
$log->id = 1;
$log->dados = ['usuario'=>'maria', 'metodo'=> 'incluirLivro', 'parametros' => ['preco'=> 7.99, 'titulo'=> 'Livro de Teste']];
$log2 = new Log();
$log2->id = 2;
$log2->dados = ['ip'=> '10.120.100.210', 'origem' => 'CHINA'];
var_dump(serialize($log2));*/
$statement = $pdo->query('SELECT dados FROM log');
$statement->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, Log::class);
$logs = $statement->fetchAll();
foreach ($logs as $log) {
echo "id: $log->id | ";
echo "dados: " . var_export($log->dados, true);
echo "<br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment