diff --git a/db.php b/db.php old mode 100644 new mode 100755 index 646f126..398b75e --- a/db.php +++ b/db.php @@ -1,8 +1,8 @@ init(); // Past this point, we're connected - yourls_debug_log(sprintf('Opened database %s ', $dbname, $dbhost)); + yourls_debug_log(sprintf('Opened database %s ', $dbname)); // Custom tables to be created upon install yourls_add_filter( 'shunt_yourls_create_sql_tables', 'yourls_create_sqlite_tables' ); @@ -52,11 +52,11 @@ function yourls_db_sqlite_connect() { yourls_add_filter( 'stat_query_dates', 'yourls_sqlite_stat_query_dates' ); // Custom stat query to get last 24 hours hits - yourls_add_filter( 'stat_query_last24h', create_function( '', 'return "SELECT 1;";') ); // just bypass original query + yourls_add_filter( 'stat_query_last24h', function() { return "SELECT 1;"; }); // just bypass original query yourls_add_filter( 'pre_yourls_info_last_24h', 'yourls_sqlite_last_24h_hits' ); // use this one instead // Return version for compat - yourls_add_filter( 'shunt_get_database_version', create_function( '', 'return "5.0";') ); + yourls_add_filter( 'shunt_get_database_version', function() { return "5.0";} ); // Shunt get_all_options to prevent error from SHOW TABLES query yourls_add_filter( 'shunt_all_options', 'yourls_sqlite_get_all_options' ); @@ -281,3 +281,11 @@ function yourls_create_sqlite_tables() { return array( 'success' => $success_msg, 'error' => $error_msg ); } + +/** + * @return \YOURLS\Database\YDB + */ +function yourls_get_db() { + global $ydb; + return ( $ydb instanceof \YOURLS\Database\YDB ) ? $ydb : yourls_db_connect(); +} diff --git a/readme.md b/readme.md index ca0930c..81d2fba 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ -# SQLite Driver for YOURLS 1.7.3 +# SQLite Driver for YOURLS 1.7.10 ## What -This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.3**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). +This is a custom DB layer that allows to use YOURLS with PDO + SQLite. This requires **YOURLS 1.7.10**, not before, not after. See [YOURLS releases](https://github.com/YOURLS/YOURLS/releases). This is experimental, mostly to show how it should be done, ie without [hacking core file](https://github.com/YOURLS/YOURLS/wiki/Dont-Hack-Core) - see [YOURLS issue #1337](https://github.com/YOURLS/YOURLS/issues/1337) (1337, for real!). @@ -10,7 +10,8 @@ If you notice something that doesn't work as expected, please open an issue with ## How -* Drop these files in `/user/`, next to your `config.php` (this is *not* a plugin) +* Enable either the **gmp** or the **bcmath** extension for PHP. +* Drop **db.php** in `/user/`, next to your `config.php` (this is *not* a plugin) * Load YOURLS: the first time, it will create a fresh SQlite DB in that same `user` directory * Have fun