Jump to content

Dealing with an error I've not seen before...


Recommended Posts

Up until a week ago the below worked just fine.  I migrated my site to a new server space, and now the below is throwing an error.  

When I remove the GROUP BY, the error goes away.  

 

I marked the line throwing the error.  

Quote

Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given in /home1/nitoaute/csi/wp-content/plugins/csi_reviews.php:1088 Stack trace: #0 /home1/nitoaute/csi/wp-content/plugins/csi_reviews.php(1088):

$query="SELECT *, e.id as eid,event
	FROM a_events e
	INNER JOIN a_players_reviews pr
		ON pr.eventID = e.id
	WHERE date_format(start, '%y') = '". $current_season ."'
	
	GROUP BY event
	ORDER BY start desc
	";

	echo '<div class="events_header"><h3>Events & Tournaments</h3></div>';
	echo '<div class="events_list">';

	
		$results = mysqli_query($con,$query);
	LINE 1088	while($line = mysqli_fetch_assoc($results)) {	
		

 

Thank you

 

the php error you are getting is a follow-on error, because the query is failing, but there is no error handling for the query. the easiest way of adding error handling for all the mysqli statements that can fail - connection, query, exec, prepare, and execute, is to use exceptions for errors (this is the default setting now in php8+). to enabled exceptions for the mysqli extension, add the following line of code before the point where you make the database connection (or upgrade to php8) -

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

you should then be getting an uncaught exception error with the raw database error information in it about a non-groupby/non-aggerate column being referenced. the correct way of fixing this is to a) only select the columns you are using, and b) every column you are selecting needs to be either in the GROUP BY term or used in an aggerate function. there is a database server mode setting that control if this condition produces a query error (the current setting) or if it is just a warning. you may or may not have access to this database mode setting. 

I'm getting a lot of this...

Quote

Fatal error: Uncaught mysqli_sql_exception: In aggregated query without GROUP BY, expression #55 of SELECT list contains nonaggregated column 'nitoaute_csi.po.id'; this is incompatible with sql_mode=only_full_group_by in /home1/nitoaute/csi/wp-content/plugins/csi_custom.php:1266 

The GROUP BYs are what is causing this, at least that's what reflected in the errors.  

 

 

The above code, doesn't have a current instance, but it still shouldn't throw an error.  I'm not sure if anything has changed with PHP 8.2 or MySQL 8+ to cause these errors.  I read something about a column in the GROUP BY not specifically called in the SELECT.  I would say that has never given me an error before, even though it makes sense.  

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.