Re: Am I missing something important here ?
| From: | Darren | Date: | Thu, 24 May 2001 10:43:24 +0000 |
| Subject: | Re: Am I missing something important here ? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-9601@lists.php.net to get a copy of this message | ||
"annabelle.imray" <annabelle.imray@ntlworld.com> wrote in message
news:9ehff1$jda$1@toye.p.sourceforge.net...
> I have been given an example of how to use php & mysql from a hosting
> company. They have the following function:
>
> #====
> function ExecuteQuery ($linkdb, &$queryresult, $querytext) {
>
> $queryresult = mysql_query($querytext, $linkdb);
>
> if (($queryresult != false) and (mysql_errno() == 0)) {
> return true;
> } else {
> return false;
> }
> }
> #====
>
> And an example of it's usage:
>
>
> $query = "SELECT * FROM test";
>
> if ($mysql_result = mysql_query($query, $linkdb)) {
> if (ExecuteQuery($linkdb, $result, $query)) {
> while ($row = NextRow($result)) {
> print('"'.$row[1].'" :
> "'.$row[2].'"<br>');
> }
> }
> }
>
> Can anyone tell me why the first "if" exists in their usage example, e.g.
if
> ($mysql_result = mysql_query($query, $linkdb)) {
>
> As the $mysql_result variable is not used after this statement and the
query
> is performed again in the ExecuteQuery() function;
>
> As I have said, am I missing something important here?
>
> Thanks
What wasteful code. It seems to execute the same query twice
It would be more practical to return the result of the query in the function
then you can remove the first 'if' then
good luck