关于结果的PHP / MySQL警告 [英] PHP/MySQL warnings about results
问题描述
我已经创建了一个函数来将所有结果作为结果数组获取 -
数组。通过mysql_fetch_array获取结果数组很简单,并且
函数本身非常简单,如下所示:
函数db_query($ db,$ query)< br $>
{
$ result = mysql_query($ query,$ db);
$ res_array = array();
>
if($ result)//这是一个搜索
{
while($ data = mysql_fetch_array($ result,MYSQL_ASSOC))
array_push($ res_array,$ data);
}
返回$ res_array;
}
但是有一个小问题:当有问题的查询是INSERT,
UPDATE或DELETE查询时,PHP会向我显示一条警告说:
警告:mysql_fetch_array():提供的参数不是/ home / grad / ccomp / 06 / guedesav / public_html / PbBlog / inc /中的有效MySQL
结果资源
db.php第28行
(第28行是while($ data = mysql_fetch_array($ result,MYSQL_ASSOC)))
并在HTML outp上发出此警告ut导致不可能
使用header(),例如,回到post删除页面。如果我的结果是和INSERT /
UPDATE / DELETE而不是SELECT查询,那么
有什么方法可以提取吗?
db,
查询)
{
< blockquote> result = mysql_query(
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))")
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?
db,
query)
{
result = mysql_query(
这篇关于关于结果的PHP / MySQL警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!