How to make Joomla! MySQL 5 compatible

If you have any 'mechanical' forge related issues/suggestions, pop them in here.
Post Reply
vaan
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Feb 09, 2006 4:41 pm

How to make Joomla! MySQL 5 compatible

Post by vaan » Thu Feb 09, 2006 5:02 pm

After you've installed Joomla on a system that runs MySQL 5.* you might get errors when php tries to run certain queries.

On of the errors i immediately found after clicking on the 'All Content Items' menu was this one:
Unknown column 'cc.name' in 'field list' SQL=SELECT c.*, g.name AS groupname, cc.name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author FROM ( jos_content AS c, jos_categories AS cc, jos_sections AS s ) LEFT JOIN jos_groups AS g ON g.id = c.access LEFT JOIN jos_users AS u ON u.id = c.checked_out LEFT JOIN jos_users AS v ON v.id = c.created_by LEFT JOIN jos_content_frontpage AS f ON f.content_id = c.id WHERE c.state >= 0 AND c.catid = cc.id AND cc.section = s.id AND s.scope = 'content' ORDER BY s.title, c.catid, cc.ordering, cc.title, c.ordering LIMIT 0, 30

The source for this error is that MySQL 5.0 has a more strict implementation of the SQL:2003 standard. Therefore the less strict SQL statements fail.

The 'bug' can easily be fixed by the Joomla developers by adding some parenthesis. I'll give as an example of one the changes i've made to admin.content.php:

1) Lookup the old code. It should look like this:

Code: Select all

   $query = "SELECT c.*, g.name AS groupname, cc.name, v.name AS author"
   . "\n FROM #__content AS c, #__categories AS cc, #__sections AS s"
   . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
   . "\n LEFT JOIN #__users AS v ON v.id = c.created_by"
   . ( count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : '' )
   . "\n ORDER BY c.catid, c.ordering"
   . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
   ;


2) Then replace it with:

Code: Select all

   $query = "SELECT c.*, g.name AS groupname, cc.name, v.name AS author"
   . "\n FROM (#__content c, #__categories cc, #__sections s)"
   . "\n LEFT JOIN #__groups AS g ON (g.id = c.access)"
   . "\n LEFT JOIN #__users AS v ON (v.id = c.created_by)"
   . ( count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : '' )
   . "\n ORDER BY c.catid, c.ordering"
   . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
   ;

Notice the parenthesis arround the table names in the FROM part and the field names in each of the ON parts.

3) Do this for all the SELECT statements where LEFT JOINS and INNER JOINS are used.

That is all!

Good luck developers!

User avatar
miki89
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Wed Jan 04, 2006 3:28 pm
Location: Milan, Italy

Re: How to make Joomla! MySQL 5 compatible

Post by miki89 » Thu Feb 09, 2006 6:13 pm

joomla 1.1 will try to support MYSQL5, as i read in the roadmap
Imagination is more important than knowledge... (Albert Einstein)

vaan
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Feb 09, 2006 4:41 pm

Re: How to make Joomla! MySQL 5 compatible

Post by vaan » Mon Feb 13, 2006 7:53 am

miki89 wrote:joomla 1.1 will try to support MYSQL5, as i read in the roadmap


So've noticed. I may have posted prematurely, a common problem for men of my age :-[


Post Reply