简体   繁体   中英

How to use Adminer Editor with SQLite?

I want to use the 'light' version of Adminer called Adminer Editor to access a SQLite3 database file in the same directory.

The documentation on the official website doesn't seem to be too extensive and I am still trying it took me a long time to find a working solution.

I was able to overcome the None of the supported PHP extensions (SQLite3, PDO_SQLite) are available. error.

Later I was stuck at the Database does not support password. error.

After this I was confronted with the attempt to write a readonly database error.

I hope my experience will help other people using adminer editor.

My system is Manjaro based on Archlinux, some of the commands might be different for your system.

  1. Install php-sqlite: sudo pacman -S php-sqlite
  2. Activate the SQLite driver for php by editing /etc/php/php.ini :
    uncomment the line ;extension=sqlite3 by removing the ; .
  3. Restart apache, in my case: sudo systemctl restart httpd.service .
  4. You can check if SQLite is active in php by writing <?php phpinfo(); into a php file and open it in your browser.
  5. Download the adminer-editor source file from the Adminer Editor page and rename it to adminer-editor.php .
  6. Download plugin.php and login-password-less.php from the Plugins page and put them into the plugins subfolder.
  7. If you don't have a SQLite database file you can create it with sqlite3 database.db in terminal.
  8. Download the sqlite.php file from the adminer github repository and save it as index.php .
  9. Your folder structure should be like this:
    adminer-editor.php
    database.db
    index.php
    plugins/
           |__ login-password-less.php
           |__ plugin.php

  1. Edit your index.php file. The content of my file is this:
<?php
function adminer_object() {
  
  include_once "plugins/plugin.php";
  include_once "plugins/login-password-less.php";
  
    class AdminerCustomization extends AdminerPlugin {
        function loginFormField($name, $heading, $value) {
            return parent::loginFormField($name, $heading, str_replace('value="server"', 'value="sqlite"', $value));
        }
        function database() {
            return "database.db";
        }
    }
    
    return new AdminerCustomization(array(
        // TODO: inline the result of password_hash() so that the password is not visible in source codes
        new AdminerLoginPasswordLess(password_hash("password", PASSWORD_DEFAULT)),
    ));
}
include 'adminer-editor.php';
  1. You can now browse to your index.php, leave the Username field empty and enter the password equal to the one in your index.php .

edit : Some things to note:

  • The folder containing the SQLite database file must give appropriate write permissions so that a lock file can be created next to the database file at any time you are using it. A good solution might be to put the database file in its own subfolder. Make sure that the file itself can not be accessed from the web, maybe using .htaccess and/or.htpasswd files.
  • Some text editors will break the translation functionality in the adminer php files after editing them. If this happens to you, re-download the original file and use a different editor. In my case, micro did break them, nano didn't.

Some questions that are left on my side:

  • Is there a way to set different Usernames for different users?
  • What does the // TODO line mean; Is there a way that I don't have to store the password in plain text in my index.php file?
  • Any other improvements you would like to suggest?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM