php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54008 mysql_fetch_assoc() expects parameter 1 to be resource
Submitted: 2011-02-13 17:17 UTC Modified: 2011-02-13 18:02 UTC
From: lucas dot tettamanti at gmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.3.5 OS: Linux Mint 10 (Julia)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lucas dot tettamanti at gmail dot com
New email:
PHP Version: OS:

 

 [2011-02-13 17:17 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-13 18:02 UTC] kalle@php.net
-Status: Open +Status: Bogus
 [2011-02-13 18:02 UTC] kalle@php.net
You need to check the return value of mysql_query() for errors as it won't magically emit one -> Bogus.
 [2011-02-14 01:21 UTC] lkzwieder at hotmail dot com
p.tamaño ---> change the name of this field in database... I'm sure that the query works fine in MySql, but PHP doesn't accept ñ in the key of an array.

Thats the problem...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC