Skip to content

Instantly share code, notes, and snippets.

@rinatio
Created June 10, 2013 11:29
Show Gist options
  • Save rinatio/5748116 to your computer and use it in GitHub Desktop.
Save rinatio/5748116 to your computer and use it in GitHub Desktop.
$db = $this->getContext()->getDB();
$dbConf = $this->getContext()->getConf()->database;
$dbh = new PDO("mysql:host=$dbConf->host;dbname=$dbConf->database", $dbConf->username, $dbConf->password);
$sql = "update runresults set report_html = :report where id = :id";
$q = $dbh->prepare($sql);
$q->execute(array(
':report'=>gzencode('hello'),
':id'=> 1052
));
$sql="SELECT report_html FROM runresults WHERE id = 1052";
$result = $dbh->query($sql);
$row = $result->fetch(PDO::FETCH_NUM);
// Example 1
// report_html is not encoded properly that's why we see an error in browser
header( 'Content-Encoding: gzip' );
echo $row[0];
// Example 2
// This code throws a warning saying "error in data"
echo gzdecode($row[0]);
// Example 3
// This code works properly
header( 'Content-Encoding: gzip' );
echo gzencode('hello');
// Example 4
// And this works alright too:
echo gzdecode(gzencode('hello'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment