Adminer有点类似PhpMyAdmin,不过更短小精悍,支持的数据库类型也比较多。

下载安装

说其短小精悍,是因为最后打包生成的只有单个php文件,可以直接使用。

下面以Adminer的英文版合成php为例:

php -S 127.0.0.1:8111 adminer-4.7.6-en.php

可以在浏览器中访问127.0.0.1:8111既可以看到控制台页面。

但是这个单个打包的文件不带plugins,为了使用plugins,必须额外加载。

以使用插件LoginToASqlite3DatabaseWithoutCredentialsWithAdminer为例,需要将下面两个文件下载到plugins目录:

然后写一个index.php文件,在加载adminer-4.7.6-en.php之前先加载plugins:

<?php
function adminer_object() {
    // required to run any plugin
    include_once "./plugins/plugin.php";
    
    // autoloader
    foreach (glob("plugins/*.php") as $filename) {
        include_once "./$filename";
    }
    
    $plugins = array(
        // specify enabled plugins here
        new FCSqliteConnectionWithoutCredentials(),
    );
    
    /* It is possible to combine customization and plugins:
    class AdminerCustomization extends AdminerPlugin {
    }
    return new AdminerCustomization($plugins);
    */
    
    return new AdminerPlugin($plugins);
}

// include original Adminer or Adminer Editor
include "./adminer-4.7.6-en.php";
?>

然后在index.php所在目录执行下列命令即可

php -S 127.0.0.1:8111

使用LoginToASqlite3DatabaseWithoutCredentialsWithAdminer插件是因为Adminer要求访问数据库必须提供密码,虽然SQLite不需要密码。参考https://www.adminer.org/en/password/

使用dg/adminer-custom包

dg/adminer-custom是一个预先配置好的adminer,可以通过composer安装使用:

composer require dg/adminer-custom

创建一个adminer目录,制作一个index.php文件,内容如下:

<?php
require __DIR__ . '/../vendor/dg/adminer-custom/index.php';

同时在adminer目录下创建一个空的adminer.css。

执行下面命令启动服务:

php -S 127.0.0.1:8011 -t adminer\

使用vrana/adminer包

如果需要使用adminer的API,可以使用Composer安装vrana/adminer。然后执行下面这条命令来启动服务:

php -S 127.0.0.1:8111 -t vendor\vrana\adminer

可以在http://127.0.0.1:8111/adminer/index.php访问Adminer控制台。

不过需要注意,adminer/index.php里面都是以相对路径来访问其他php文件。为了避免找不到文件,可能需要使用composer的autoload功能来矫正路径。

参考

其他支持SQLite的工具

(完)