var_dump and sizeof database entry?

var_dump and sizeof database entry?

am 05.01.2006 23:19:43 von Jordan Miller

Hello,

This is stumping me something awful. I have searched the archive of
this mailing list and google and the php and mysql websites with
everything i can think of.

I have a simple mysql table with some basic columns and a blob column
that holds an image file. What I need to get is the size of this
image file for use with an rss feed (the enclosure "length" parameter).

In the simplest case, I thought I would just read the entire blob
into a variable, and then I would be able to get the size of this
variable. However, php does not seem to have a function to do this.
Inexplicably, the "var_dump" command will actually dump the
information I want, but it is very memory inefficient, because I get
something like:
["preview"]=> string(17888) "ENTIRE CONTENTS OF BLOB HERE"

where all I really want is the 17888 value (for a 17.5 KB file).

What I was wondering is if there is a simple way to get this
information from mysql directly without having to 1) select the blob
column and 2) do a var_dump with output buffering and parsing for the
parenthetical file size, which seems very inefficient to me.

any insight is greatly appreciated.

Jordan

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: var_dump and sizeof database entry?

am 06.01.2006 01:14:47 von Bastien Koert

I would do one of two things here:

1. add a size column to the db and have the image size added when
inserting the image

2. run a trash script (either sql if your version support subselects or a
little page) to get the size of
the image and enter it into the size field

Another option is to use

select *, (length(image_fiedl)/1024) as Kb from table [where clause] to get
the size

Bastien


>From: Jordan Miller
>To: PHP DB
>Subject: [PHP-DB] var_dump and sizeof database entry?
>Date: Thu, 5 Jan 2006 16:19:43 -0600
>
>Hello,
>
>This is stumping me something awful. I have searched the archive of this
>mailing list and google and the php and mysql websites with everything i
>can think of.
>
>I have a simple mysql table with some basic columns and a blob column that
>holds an image file. What I need to get is the size of this image file for
>use with an rss feed (the enclosure "length" parameter).
>
>In the simplest case, I thought I would just read the entire blob into a
>variable, and then I would be able to get the size of this variable.
>However, php does not seem to have a function to do this. Inexplicably,
>the "var_dump" command will actually dump the information I want, but it
>is very memory inefficient, because I get something like:
>["preview"]=> string(17888) "ENTIRE CONTENTS OF BLOB HERE"
>
>where all I really want is the 17888 value (for a 17.5 KB file).
>
>What I was wondering is if there is a simple way to get this information
>from mysql directly without having to 1) select the blob column and 2) do
>a var_dump with output buffering and parsing for the parenthetical file
>size, which seems very inefficient to me.
>
>any insight is greatly appreciated.
>
>Jordan
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: var_dump and sizeof database entry?

am 06.01.2006 01:51:20 von Jordan Miller

whoa, that was EXACTLY what I needed. Thanks!!
Jordan



On Jan 5, 2006, at 6:14 PM, Bastien Koert wrote:

> select *, (length(image_fiedl)/1024) as Kb from table [where
> clause] to get the size
>
> Bastien

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php