Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

911 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