Manipulating Blob Fields
am 09.01.2008 00:03:22 von Alan Bannister
------=_NextPart_000_00D4_01C8524A.AB25AE10
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi, this is my first posting to this group, so I hope it gets to the right
place!
I have been experimenting with uploading image files and storing them in a
mySQL database table.
So far I have been able to upload and extract data from an image file, add
it to the database and subsequently display it. I can also resize, etc. so
long as I have the original file to process.
What I cannot fathom is how to do this by reading image data stored in a
blob field in the table rather than a file. Most of the image functions
seem to need a file as the source.
Anyone help a newbie?
Alan Bannister
------=_NextPart_000_00D4_01C8524A.AB25AE10--
RE: Manipulating Blob Fields
am 24.01.2008 17:44:01 von Alan Bannister
Not a lot of feedback to my original enquiry, but nevertheless I found the
answer, which I shall pass on in case it is of use to others.
The essential function is imagecreatefromstring() Using this in conjunction
with other functions allows an image string that has been stored in a
database to be converted into a format that can be exported as a file,
manipulated and returned to the database, or whatever.
All very obvious when you know how, but it takes some finding if you don't
know what you are looking for!
Alan Bannister
-----Original Message-----
From: Alan Bannister [mailto:alan.bannister@btinternet.com]
Sent: 08 January 2008 23:03
To: php-db@lists.php.net
Subject: [PHP-DB] Manipulating Blob Fields
Hi, this is my first posting to this group, so I hope it gets to the right
place!
I have been experimenting with uploading image files and storing them in a
mySQL database table.
So far I have been able to upload and extract data from an image file, add
it to the database and subsequently display it. I can also resize, etc. so
long as I have the original file to process.
What I cannot fathom is how to do this by reading image data stored in a
blob field in the table rather than a file. Most of the image functions
seem to need a file as the source.
Anyone help a newbie?
Alan Bannister
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Manipulating Blob Fields
am 14.02.2008 09:47:22 von Julian
Hi Alan,
Sorry not writing to help you out.
I am trying to do something like you, but with pdf files. I am no expert
on mysql but I just can't manage to store a pdf file in a blob field.
Any hints or experiences to share ??
I use a sequence of prepared statements, no rocket science precisely.
$stmt=$db->prepare("UPDATE `julian2`.`inscripcion` SET `resguardo`=?
WHERE `inscripcion`.`id`=3 limit 1");
if($stmt==false){
throw new Exception("error prepare database",200);
}
$stmt->bind_param("b",$pdfdata);
$ret=$stmt->execute();
No errors, warning, nothing. At the end however, there is no data in the
field.
I am using php 5.2 and MySql 5
Any help appreciated.
Thanks.
JCG
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Manipulating Blob Fields
am 14.02.2008 11:24:36 von Julian
After some research I found a workaround, not a solution. Diggin in
www.php.net I found the following (potential) bug apparently resolved
time ago
http://bugs.php.net/bug.php?id=35155
in relation to
Bug #35155 prepared statement with blob field does not work
Which is exactly what it is happening to me. It refers to the use a
function mysqli_stmt_send_long_data.
Apparently you only need to use this function if your data is larger
than max_allowed_packet, which in my system is 16MB.
The fact is, it is the only way I have managed to store pdfs files in
the field. My pdf files a very small < 5Kb.
Happy to have it working, but hesitant to understand why....
Regards.
JCG
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Manipulating Blob Fields
am 14.02.2008 12:25:12 von Oskar
-------- Original Message --------
Subject: Re: [PHP-DB] Manipulating Blob Fields
From: julian
To: php-db@lists.php.net
Date: 14.2.2008 11:24
>
> After some research I found a workaround, not a solution. Diggin in
> www.php.net I found the following (potential) bug apparently resolved
> time ago
> http://bugs.php.net/bug.php?id=35155
> in relation to
>
> Bug #35155 prepared statement with blob field does not work
>
> Which is exactly what it is happening to me. It refers to the use a
> function mysqli_stmt_send_long_data.
>
> Apparently you only need to use this function if your data is larger
> than max_allowed_packet, which in my system is 16MB.
>
> The fact is, it is the only way I have managed to store pdfs files in
> the field. My pdf files a very small < 5Kb.
>
> Happy to have it working, but hesitant to understand why....
>
> Regards.
>
> JCG
>
I had similar problem. I needed to insert few thousands of rows.
The code looked like this:
$buffer = '';
$buffer_length = 0;
$max_packet_size = 750000;
for ($i = 0; $i < sizeof($inserts); $i++)
{
$current_values = '(' . $inserts[$i]['col1'] . ', ' .
$inserts[$i]['col2'] . ', ' . $inserts[$i]['col3'] . ')';
if (($buffer_length + strlen($current_values)) > $max_packet_size)
{
if (!mysql_query($buffer, $connection))
{
// error handling
}
$buffer = '';
$buffer_length = 0;
}
$buffer .= ($buffer != '') ? ", $current_values" : "INSERT INTO
table (col1, col2, col3) VALUES $values";
$buffer_length += strlen($current_values);
}
It was interesting that although MySQL's internal max_packet_size was
more than 1 MB I was able to send only about 100kb long query. I have
never figured out why does this happen
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php