Solved

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

Posted on 2010-11-11
3
836 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

696 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