Jump to content

whats better?


ohdang888

Recommended Posts

ok thanks. will do.

 

But just wondering, for learning purposes, how to echo the file...

 

i have a picture saved in a blob in a table, and to extract and show i use this:

 

$r = mysql_query("SELECT * FROM test")or die(mysql_error());

while($row = mysql_fetch_array($r)){

echo $row['id'];

}

 

and all it shows is this:

GIF89a–�–�æ��"¨¨¨??? žccc$$$ƒËËÌ((0»»¼111ïïï<?G<<‡Ï%¡B•„Œ Ï¡Ó±”€(Ë¡XRRT€‹)c;ÒÔ˜2cQ³¹œ@¿ôÜôhÎO†b:`´©„J+½tj´H…¨“¦R5f ÖG,nuŠåk£ic©"1Û¨XÚ¦dÿ&²U„ö­Q)s}´kÔDÞD{ùæœáào!Ü ÎÂ0!‹›úu,HCd£P)¸´åAœs–K9tΫšMË´ðù¤ê”L>3}ÒÀg†´AÚ¦Œ;7ÆÝŽ{ûnÜ°ðá‹ÿuœøç2Í*ÿ«8º¾éyëZ—‡}îìíò2Pø¼¼¾ñŸk™‡šrÑõ×€<ÿÿZ‰1Ÿ1Ô?¥õ~s^¤÷_9M¤6à5\PÆÜÆŒ¦ ƒÕxö „Æá…tñ…fð\Õ hÄ‡Ú 8yÒðaê HØŠôÁ§„*®Èâ~�Xaã ‚@ ;¢u�IHŒÖ¥`¤ÿëÙ°$.ï5Å“„@ À•–!ç$•‡@6\rœjJ†YH–¾if!N§æšƒT‘æ›p–Ñ£itÖyghy Ašurm�ôYg¯Z'�‰j£ª) '¤x:Z¥|ZJ¦œIº&§—yj&¨‘‰Êe¡‰šº$ª„ªº#«¹Z'¤FÊœ:X§Ã§7Xwƒ«”Õë¨>†„°„A%¬ÛÉd¡ÈºéìsЭcTK!´°Å€Ñ€ÝåÀìÀa<;DTXGTðÁº}PA÷PC?Ð‹Ñ Ä€^3ô°¿)mо²´pÁçôÂ-°¢À®DÜÔC�„ h¼Õå’¢‚ˆ<¨ Š2 ²]$Èàñ& XpBÊ3ÆÁ Ü\ ÜshdÀÓ$!À ÂÑ´‰�CcŽP€C!CíÛà0ð!|µÖÑ-ðÄ8d¯çCï& wÛûÉ�Ýxç­÷Þ|÷í÷߀.øà„nøáˆ'®øâŒ7îøãG.ùä”Wnùå˜g®ùæœwîùçy

 

 

Thanks!

 

Link to comment
Share on other sites

nevermind,  got it working:

 

$content = $row['id'];

 

header('Content-type: image/gif');

echo $content;

 

 

Two more questions:

 

what if the table is only pictures... it wouldn't slow it down that much would it?

 

How much better is it to be to use the url?

Link to comment
Share on other sites

Storing images would take up memory, and not to mention space.

 

It also increases the query times. If you store text, it makes things easier (it also requires no headers) and so you can adjust how you want your images to be (size, hieght etc)

 

Just store the the text.

Link to comment
Share on other sites

Storing images would take up memory

 

How would it use memory (I'm assuming you mean RAM)?  Unless you are indexing a blob...which is pointless (and I'm not sure it's possible). 

 

, and not to mention space.

 

They are going to use HDD space regardless of where they are stored.

 

It also increases the query times.

 

Again, how?  It may increase the amount of time it takes the query results to move across the network from the DB server to the web server, but the query times would not be impacted.  The exception to this may be if you issue a query with a WHERE clause on an unindexed field and MySQL has to do a full table scan, which would cause it to have to read all the data off the disk.

 

If you store text, it makes things easier (it also requires no headers)

 

The easier part is a matter of opinion...some people prefer to just backup the database and not have to worry about a huge file system.  The headers part is true...when you have the image stored in the DB you have to have a seperate php script to query the database for the image data, then issue image headers and stream the data to the browser.

 

and so you can adjust how you want your images to be (size, hieght etc)

 

That can be done regardless of where the image is stored.

 

Where to store the images is a matter of opinion primarily.  There have been many many arguments between people about which is better.  I, personally, use the file system.  Database's generally have expensive storage...where I work the Apache servers have 10k SATA drives, the DB servers have 15k SCSI drives...and depending on what else the database is doing, you may not want it to have to devote CPU cycles to querying and sending images...it's much more difficult (generally speaking) to add additional computing power to a DB (horizontal scaling is one of the few options), however it's very easy to stand-up a new Apache server to server static images.

 

Link to comment
Share on other sites

@hitman6003

 

the memory that marklarah is talkin bout is the memory taken from the database. you see, if you store only the path, the memory eaten is less compared with the picture itself. yes, it would still eat up your memory in HDD but we are talkin about database.

 

we all know database has limits in size, though very big imaginable but you are wasting a lot of space which is totally unnecessary.

 

queries are longer, indeed. fetching a larger data is longer. why not give that problem of loading to others instead of the database server... as for me, the less time you communicate with the database server is better since there are a lot of other users that utilize that database (if one is really into it), say there are other software programs and/or sites that use those information.

 

also, why have the headache of parsing a certain image rather giving them to the browsers to deal with it (since with blog, its up to you to decode the contents to the specified format needed)?

 

in terms of viewability... anytime a person needs a picture of someone or something, for whatever purpose you use that picture, you can easily get it rather than creating queries.

 

summary:

we don't need to give the database server additional unnecessary effort, especially if the server itself is already too full of itself. :)

 

IMO,

Link to comment
Share on other sites

hitman

 

ohdang's sql

 

SELECT * FROM test

 

is where it slows it down

 

as I understand it because there is no where clause in there MySQL is queueing up the ENTIRE table, which could be huge and have thousands of fields/records/rows whatever

 

add a WHERE id = 1 to the end of that and the query only returns one row, making it hugely faster on a big table

 

//noob opinion

Link to comment
Share on other sites

the memory that marklarah is talkin bout is the memory taken from the database. you see, if you store only the path, the memory eaten is less compared with the picture itself.

 

Again, just storing information in a database does not cause it (i.e. the database or the table) to consume RAM...the only time data is stored in RAM is when the column is indexed.

 

Of special interest here is InnoDB's B-Tree indexes.  The leaves for an InnoDB primary key index store the data itself, so long as it doesn't exceed the size of the leaf (which, if I recall correctly, is 16KB), and the field is not a, or variant of, TEXT or BLOB (might be others that I don't remember off-hand).  Secondary indexes store pointers to the primary key, which in turn, follows the above behavior of storing the data in the leaf.

 

MyISAM indexes, conversely, simply index the column and store a pointer to the data on disk. 

 

we don't need to give the database server additional unnecessary effort, especially if the server itself is already too full of itself

 

Agreed, wholeheartedly...databases are much more expensive that web servers...they require higher paid admins, better storage, more RAM/CPU...so fiscally speaking, it doesn't make sense to use them for something as mundane as image serving.  However, it's not impossible, and in some cases, is needed (what the easiest way to securely store documents without having to encrypt each one individually?  Dump them into an encrypted table).

Link to comment
Share on other sites

Again, just storing information in a database does not cause it (i.e. the database or the table) to consume RAM...the only time data is stored in RAM is when the column is indexed.

 

its not that am talkin bout just from the accessing. each database has certain limit. the more you store pictures into the database, the faster it will grow. why store pictures in the database when it will only add additional memory into the database when you can just made it as file and store only the path? of course, pictures are not that hard to find if you have indexed it but would take longer to be fetched than just a filename, not to mention that you need to decode it to a picture before displaying it.

 

storing documents, especially having them enrypted is a different thing from picture. yes, blob is very useful. i once used this when i need to store an important information in a spreadsheet.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.