php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9274 Error with inserting a binary data into database
Submitted: 2001-02-15 06:35 UTC Modified: 2001-06-02 22:25 UTC
From: mgx at frcatel dot fri dot utc dot sk Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.0.4pl1 OS: Win XX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 + 23 = ?
Subscribe to this entry?

 
 [2001-02-15 06:35 UTC] mgx at frcatel dot fri dot utc dot sk
error occured only in PHP compiled as a module on WIn95,98
php from default win installation, no changes in php.ini
tested on many computers

problem occured while inserting images (binary data into database). Functional script under OS LINUX don't work, because process of importing a binary data (for example gif
image) is stopped when PHP detect some 'special' character.
the same thing happend while trying to open binary data with file functions

good code /tested on Linux and on cgi version of php under win/

 create database pokus;
create table pokus(pole blob);

insert.php - it doesnt import whole image!

<? 
$subor = "b.gif"; 
$fp = fopen($subor, "r"); 
$data = addslashes(fread($fp, filesize($subor))); 
fclose($fp); 
$data = "insert into pokus values ('$data')"; 
$conn = mysql_connect("localhost", "root", "root"); 
$vysledok = mysql_db_query("pokus", $data); 
?>

script for showing image

<? 
Header("Content-type: image/gif"); 
$conn = mysql_connect("localhost", "root", "root"); 
$vysledok = mysql_db_query("pokus", "select * from pokus"); 
$z = mysql_fetch_array($vysledok); 
echo $z[pole]; 
?> 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-02 22:25 UTC] sniper@php.net
If you want binary safety within Windows, you have
to tell it to open the file in such mode.

$fp = fopen($subor, "rb");

RTFM.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jan 24 18:03:35 2022 UTC