How to get the drupal version using query ? Or how do we detect using query the drupal version is 7,6,5 or 4?
This will work with Drupal 7 - I don't have other version to test it on but think it should work...
Because the version is stored in the text file CHANGELOG.txt we can write that to a table in the DB, read from the table, and then delete it again afterwards:
First run this: (make sure to change the path to your changelog file)
This will return something like:
And run this to delete the table we just made:
Whilst this is a long winded way of reading text from a text file it is strictly speaking getting the version using MySQL...
As Topsitemakers suggested looking in the system table I had a look and found the version was hidden in there, but only against specific modules. I figured the field module would be in all version of drupal, however I very highly doubt that this query will actually work on any version other that 7 as it's so specific and a bit of a beast:
For me this query returns:
This should work for D7 and D6, i don't have other versions to test but if system table is similar, it should work as well.
This will get something like "7002" or some number starting with a 7 for Drupal 7 and "6005" or something starting with 6 for Drupal 6. It's not the exact running version but if you just have a database dump you can figure out from where it comes from.