Solved

PHP Fatal error:  Call to a member function fetch_assoc() on a non-object on line 19

Posted on 2010-11-11
3
824 Views
Last Modified: 2013-11-13
This work with a die statement.  I put the die statement for testing.  But once I remove the die statement for it to continue processing, I get the php fatal error.  I tried to free the result set or close it, but it is still complaining.

See my code:

$mysqli = @new mysqli($db_host, $db_username, $db_password, $db_name);

$sql = "select * from table1";
$dataIndex = $mysqli->query($sql);

while ($result = $dataIndex->fetch_assoc())
{
      $field1 = $result['index_short_name']."_field1";
      $field2 = $result['index_short_name']."_field2";
      
      $sqlData = "select new_date, ".$field1.", ".$field2."  from table2";      
      $dataFund = $mysqli->query($sqlData);
      
      while ($row = $dataFund->fetch_assoc())
      {
            $line = "";
            $line .=  $row['new_date'].",".$row[$field1].",".$row[$field2]."\n";
            echo "<p>".$line."</p>";
            
      }
      die("here");
}

I replace the die("here") with $dataFund->close() and still error.
0
Comment
Question by:bigjdve
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 125 total points
ID: 34116110
It appears that you can't do nested queries. http://php.net/manual/en/mysqli.query.php in the middle of the page says "/* Note, that we can't execute any functions which interact with the server until result set was closed. All calls will return an 'out of sync' error */".
0
 
LVL 13

Expert Comment

by:dsmile
ID: 34117626
You should put error check to each query you have

$dataIndex = $mysqli->query($sql);
if (!$dataIndex ) {
   die('Invalid query: ' . mysql_error());
}


$dataFund = $mysqli->query($sqlData);
if (!$dataFund ) {
   die('Invalid query: ' . mysql_error());
}

I think one of those loops might meet empty result and it causes that error
0
 
LVL 3

Author Closing Comment

by:bigjdve
ID: 34231254
Basically, you can not do nested queries.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now