Reputation: 409
I know this question already asked, but I can't solve my problem, so I explained my problem here kindly help me to solve this.
I am getting data form this example URL by using file_get_contens()
$URL1 = 'abcd.com/xxx';
$URL2 = 'abcd.com/yyy';
$URL3 = 'abcd.com/zzz';
$response1 = file_get_contents($URL1);
$response2 = file_get_contents($URL2);
$response3 = file_get_contents($URL3);
And I compressed response data using gzencode because data too long and added prefix for my reference then i save compressed data to DB
$arrayResponse['URL1'] = '_|_coMpResSed_|_' . gzencode($response1);
$arrayResponse['URL2'] = '_|_coMpResSed_|_' . gzencode($response2);
$arrayResponse['URL3'] = '_|_coMpResSed_|_' . gzencode($response3);
DB details
And I decompress the data by using gzdecode
$temp1 = explode('_|_coMpResSed_|_', $arrayResponse['URL1']);
$temp2 = explode('_|_coMpResSed_|_', $arrayResponse['URL2']);
$temp3 = explode('_|_coMpResSed_|_', $arrayResponse['URL3']);
if (!empty($temp1[1]) && !empty($temp2[1]) && !empty($temp3[1])) {
$arrayResponse['URL1'] = gzdecode($temp1[1]);//working fine
$arrayResponse['URL2'] = gzdecode($temp2[1]);// getting warning
$arrayResponse['URL3'] = gzdecode($temp3[1]);//working fine
}
And I am getting `Warning:
gzdecode(): data error
on line
$arrayResponse['URL2'] = gzdecode($temp2[1]);`
Other lines are working fine . I dont know where I am making mistakes. Can any one help me to get this?
Upvotes: 1
Views: 11998
Reputation: 1348
Having same problem, I just had a look at Mysql doc: https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html
Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type. This will avoid potential problems with trailing space removal or character set conversion that would change data values, such as may occur if you use a nonbinary string data type (CHAR, VARCHAR, TEXT).
I just change the column data type to VARBINARY and everything's OK.
Upvotes: 1