How to extend the administrator to support SQLite databases with login?

I am running a server that hosts both a MySQL instance (with multiple databases) and some SQLite files. I would like to use Adminer to manage all of them, provided that users set valid credentials. In addition, a list of databases should be completed.

In the case of MySQL, valid database users can be used, and the connection works out of the box. However, SQLite support must be added explicitly. The administrator reports this error:

Implement login() method to use SQLite.
  • How to extend a class Adminerto enable SQLite login?
  • What to do to fill out a list of valid databases?
+4
source share
1 answer

This answer applies to admin version 4.2.5. Unfortunately, it is not valid for Adminer 4.3.x.

You need to override the methods loginand databasesclass Adminer, making sure that you do this only for the SQLite driver, and not in other cases. The following code provides a basic login system with a list of databases:

<?php
function adminer_object() {
    class AdminerSoftware extends Adminer {
        function login($login, $password) {
            global $jush;
            if ($jush == "sqlite")
                return ($login === 'admin') && ($password === 'changeme');
            return true;
        }
        function databases($flush = true) {
            if (isset($_GET['sqlite']))
                return ["/path/to/first.db", "/path/to/second.db"];
            return get_databases($flush);
        }
    }
    return new AdminerSoftware;
}
include "./adminer-4.2.5.php";

The code can be adapted to support multiple users. Save the file as index.phpin the same directory as it is adminer-4.2.5.php. Be sure to configure the username, password, and database paths.

Here are some important notes:

  • the method is loginincorrectly named, this is the initial check performed by the administrator
  • , , . MySQL, true
  • SQLite ,

List of SQLite Databases Displayed by Administrator

+4

Source: https://habr.com/ru/post/1685567/


All Articles