CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Working with Image using MSSQL

Print topic Send  topic

Author Message
Gena

Posts: 591
Posted: 02/09/2008, 8:31 AM

Anybody has experience with the subj?

I mean I have a MS SQL database with some Image type fields so I need to save image into that fields as binary. And sure I need to show images after in my Grid and Record. Before I have worked with path to image (not storing image inside field) so have no idea how I can implement it...

TIA
_________________
Gena
View profile  Send private message
Gena

Posts: 591
Posted: 02/13/2008, 8:10 AM

So I'am in a trubble that I am not able to INSERT some binary data using normal INSERT statement.

Like this

$datastringSmallFoto = file_get_contents($foto_small_name); //get file - binary
  
$SQL= 	"INSERT INTO foto(tipo, mime_small, foto_small, mime, foto) VALUES(" .   
		$db->ToSQL($tipo, ccsText) . ", " .   
		$db->ToSQL("jpg", ccsText) . ", " .  
                                          $db->ToSQL($datastringSmallFoto , ccsMemo) . ", " .           
		$db->ToSQL("jpg", ccsText) . ", " .  
		$db->ToSQL("", ccsText) .  ")";  
  

it gives me a error because it put binary data into INSERT! But it wrong. Have no idea to how I can do it????

so need just "load" some file and put it exactly into binary (image type) field...
_________________
Gena
View profile  Send private message
jjrjr1


Posts: 942
Posted: 02/16/2008, 4:26 PM

Hi

What you might want to try is saving the binary data as a string into a character field in your database created large enough to hold the image of use several fields.

You might need to convert the image binary data to base64 using the base64_encode() function.

I have seen this done successfully before.

Hope that helps

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
Gena

Posts: 591
Posted: 02/16/2008, 6:05 PM

Thank you, jjrjr1

May be you are right. BTW I'm tried this way:

  
$datastringSmallFoto = file_get_contents($foto_small_name);  
$dataSmallFoto = unpack("H*hex", $datastringSmallFoto);  
$sf = "0x" . $dataSmallFoto['hex'] ;  

and it work BUT I got strange result. I mean I have table with already inserted records and all old records (image fields) consists of real GIF or JPG content inside like

foto_small="GIF89aVFж   etc


but records inserted by my code consists of
foto_small="0xffd8ffe000104a464946000101 etc

so I'm confused why?? and how old records were inserted???

_________________
Gena
View profile  Send private message
Gena

Posts: 591
Posted: 02/17/2008, 7:24 AM

I have figured it out. So insert statement should looks like

INSERT INTO foto(tipo, mime_small, foto_small) VALUES('C', 'jpg', 0x4749463839610100010091ff00ffffff000000ffffff00000021ff0b41444f42453a4952312e3)

note that binary field should be passed as hex number without ' ' !
_________________
Gena
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.