Solved

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

Posted on 2010-11-11
3
777 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 82

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

706 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

18 Experts available now in Live!

Get 1:1 Help Now