You are here: Re: am I doing unnecessary operations by mysql_fetch_array? « PHP Programming Language « IT news, forums, messages
Re: am I doing unnecessary operations by mysql_fetch_array?

Posted by Michael Fesser on 08/02/07 09:04

..oO(newbie)

>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);?
>2) If i use $sql_query = "SELECT user_name from `user` WHERE (id =
>'$id')";

Don't quote $id, it's a numeric value.

>to replace line (1), do I get some better performance
>theoretically?

You need both, a mysql_query() call to query the database and a
mysql_fetch_*() call to get the results. But you could use the second
paramater of mysql_fetch_array() to specify whether it should return the
result as a numeric or associative array. By default it does both.

>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)

You shouldn't use "SELECT *" in production code, list all columns
explicitly.

Micha

 

Navigation:

[Reply to this 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

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