CodeIgniter Forums
MySQL 8 error on subselect parenthesis - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: MySQL 8 error on subselect parenthesis (/showthread.php?tid=72436)



MySQL 8 error on subselect parenthesis - dimas - 12-19-2018

Hi,

I upgraded the database from MySQL 5.7 to 8.0 and now we have some query generated by CI query builder that can't be executed.

For example:
Code:
$this->db->from("(SELECT col1 FROM table) AS alias");

generates this query:
Code:
SELECT ... FROM ((SELECT col1 FROM table) AS alias)

And it worked with 5.7 but 8.0 doesn't like the exterior parenthesis. The query needs to be:
Code:
SELECT ... FROM (SELECT col1 FROM table) AS alias

What can I do?

Thx


RE: MySQL 8 error on subselect parenthesis - Pertti - 12-19-2018

I haven't tried it, but first thing that pops in mind is, if you are not using Query Builder functionality, maybe try

PHP Code:
$result $this->db->query("(SELECT col1 FROM table) AS alias"); 

This should run the SQL query text as is.


RE: MySQL 8 error on subselect parenthesis - dimas - 12-19-2018

I use the query builder functionality, I simplified the example but the query is more complex and use ->select(), ->where(), ... If there's no other way I won't use the query builder but it's helps me to simplify the query construction.


RE: MySQL 8 error on subselect parenthesis - php_rocs - 12-19-2018

@dimas,

Have you tried it this way (https://codeigniter.com/user_guide/database/queries.html?highlight=query%20builder#query-bindings) it allows you to write more complex queries.

Here is an example complex query that I wrote for another thread... https://forum.codeigniter.com/thread-70842-post-354392.html#pid354392