Reply to Re: am I doing unnecessary operations by mysql_fetch_array?

Your name:

Reply:


Posted by gosha bine on 08/02/07 08:01

On 02.08.2007 07:51 newbie wrote:
> table `user`
> ---------------------------------------
> | id | user_name | gender |
> ---------------------------------------
>
> I can gurantee that ids in table user are unique (so each number
> correspond at most one row in the table). I have two questions
> 1) can I somehow do away with mysql_fetch_array($result);?

Yes, if you need one single field, you can use mysql_fetch_field. The
performance benefit would be negligible though.

> 2) If i use $sql_query = "SELECT user_name from `user` WHERE (id =
> '$id')"; to replace line (1), do I get some better performance

Yes, of course. Some say '*' is harmful, always list the fields you want.

> theoretically? if so, can I simply return $row; ---because
> 'user_name' is the only field being selected.
>
> $sql_query = "SELECT * from `user` WHERE (id = '$id')"; // (1)
> $result = mysql_query($sql_query);
> $row = mysql_fetch_array($result);
> return $row['user_name'];
>
> Thanks,
>



--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация