Re: PHP & MS Sql WRITETEXT inserts
From: Robert (hackajar_at_yahoo.com)
Date: 04/05/04
- Next message: Chung Leong: "Re: adding items to a list or menu"
- Previous message: R.G. Vervoort: "adding items to a list or menu"
- In reply to: Robert: "PHP & MS Sql WRITETEXT inserts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Apr 2004 13:15:29 -0700
And here's the answer - (after digging in multi-sources)
//Open File we will be importing
$file = "./images/myimage.png";
$fp = fopen($file, 'r');
$raw = fread($fp, filesize($file));
//Convert to hex string
$data = unpack("H*hex", $raw);
$buf = $data['hex'];
//Set textsize to max limit, allows large files to be imported
$query = "set textsize 2147483647";
mssql_query($query) or die();
//Push data up to database (note the '0x' before data)
$query = "INSERT INTO $database.dbo.image_data (iid, idata) values
('$iname', 0x$buf)";
mssql_query($query);
MsSql will know to sent down bianry when you select the data. Hope
this helps others like me!
Robert
hackajar@yahoo.com (Robert) wrote in message news:<895be58e.0404011725.7e8a19a9@posting.google.com>...
> Anyone know a clever way of getting binary data into a MS Sql database
> with PHP?
>
> My code that fails:
>
> --->Snip
> $query = "DECLARE @mytextptr varbinary(16)
> SELECT @mytextptr=TEXTPTR(idata)
> FROM $database.dbo.image_main
> WHERE iid='$iname'
> IF @mytextptr IS NOT NULL
> WRITETEXT apig_image_main.idata @mytextptr WITH LOG '$buf'";
>
> $result = mssql_query($query) or die();
> <---Snip
>
> Error messages:
> Warning: mssql_query(): message: Unclosed quotation mark before the
> character string '?PNG '. (severity 15) in c:\program files\apache
> group\apache\htdocs\image.php on line 58
>
> Warning: mssql_query(): message: Data stream missing from WRITETEXT
> statement. (severity 15) in c:\program files\apache
> group\apache\htdocs\image.php on line 58
- Next message: Chung Leong: "Re: adding items to a list or menu"
- Previous message: R.G. Vervoort: "adding items to a list or menu"
- In reply to: Robert: "PHP & MS Sql WRITETEXT inserts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|