开发者

php compare or mysql data?

I not sure which one would use less execution time if the user is advertising a classifieds ad and did not upload any image, a 'blank.jpg' would replace the image in HTML code.

which is: <img src="blank.jpg">

For the PHP, I use if-conditional when r开发者_高级运维ead data from mysql and replace '0' value with 'blank.jpg', would it be optimal if the database just store 'blank.jpg' value instead of '0'?


It probably won't make much difference to performance, but it does make a difference to data cleanliness. Null values should be stored as NULL.

The fact that you want to show "blank.jpg" is a display issue, not a data issue. If you want to use this data elsewhere, it'll be much more efficient to check for NULL than for "blank.jpg".


No, it's probably a better solution to do it in application code (PHP). That way the database can easily be used for more than one application, e.g., if you in the future rewrite the software or if you open other sites which you want to synchronize with this one.

Store a NULL in the database.


leave the field in mysql as null and set the schema so that is default then there is no operation if there is no image. you can test for null rather than zero or anything else. or did i miss something


If you can, store a 0 or empty string as opposed to storing a NULL value.

NULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜