Bug #54008 [Opn->Bgs]: mysql_fetch_assoc() expects parameter 1 to be resource

From: Date: Sun, 13 Feb 2011 17:02:52 +0000
Subject: Bug #54008 [Opn->Bgs]: mysql_fetch_assoc() expects parameter 1 to be resource
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158747@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54008&edit=1

 ID:                 54008
 Updated by:         kalle@php.net
 Reported by:        lucas dot tettamanti at gmail dot com
 Summary:            mysql_fetch_assoc() expects parameter 1 to be
                     resource
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            MySQL related
 Operating System:   Linux Mint 10 (Julia)
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

You need to check the return value of mysql_query() for errors as it
won't magically emit one -> Bogus.


Previous Comments:
------------------------------------------------------------------------
[2011-02-13 17:17:59] lucas dot tettamanti at gmail dot com

Description:
------------
If I change the current 'SELECT' to 'SELECT * FROM...' the script works
fine. Otherwise PHP shows me the follow warning:


Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean
given in /opt/lampp/htdocs/distri/functions.php on line 158

Test script:
---------------
function get_productos($link,$params = null){
    $query =   "SELECT p.id, p.codigo, p.nombre, f.nombre as familia,
pro.nombre as provedor, p.precio, p.tamaño, p.medida
                FROM productos p
                INNER JOIN familias f ON p.familia = f.id
                INNER JOIN provedores pro ON p.provedor = pro.id";

    $result = mysql_query($query, $link);
    $i = 0;$productos = array();
    while($data = mysql_fetch_assoc($result)){
        foreach($data as $key => $valor){
            $productos[$i][$key] = $valor;
        }
        $i++;
    }

    mysql_close($link);
    return $productos;
}

Expected result:
----------------
I expect fill the array $prod with data.

Actual result:
--------------
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean
given in /opt/lampp/htdocs/distri/functions.php on line 158


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54008&edit=1


Thread (3 messages)

« previous php.bugs (#158747) next »