Reply to Re: PHP/MySQL warnings about results

Your name:

Reply:


Posted by Sanders Kaufman on 11/21/07 20:00

"bruno_guedesav" <bruno_guedesav@yahoo.com.br> wrote in message
news:e3845f5f-57a0-4e47-b43d-403060cec833@i37g2000hsd.googlegroups.com...
> I've made a function to fetch all results as an array of result-
> arrays. Getting the result arrays is easy, via mysql_fetch_array, and
> function itself is quite simple, as follows:
>
> function db_query($db, $query)
> {
> $result = mysql_query($query, $db);
> $res_array = array();
>
> if ($result) //it is a search
> {
> while($data = mysql_fetch_array($result,MYSQL_ASSOC))
> array_push($res_array,$data);
> }
>
> return $res_array;
> }
>
> But there's a slight problem: when the query in question is an INSERT,
> UPDATE or DELETE query, PHP will show me a warning saying:
>
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in /home/grad/ccomp/06/guedesav/public_html/PbBlog/inc/
> db.php on line 28
> (line 28 is "while($data = mysql_fetch_array($result,MYSQL_ASSOC))")

When I've had this problem, I've implemented error-trapping - which I
probably should have done to start with.
The way I do it is to code something that says "if result is not an array,
don't try to perform array functions on it".
Or in your case "if connection is false, don't try to query it".






>
> and havingthis warning on the HTML output leads to be impossible to
> use header() to, for instance, go back to the post removal page. Is
> there any way to know prior to fetching if my result is of and INSERT/
> UPDATE/DELETE instead of a SELECT query?

[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

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