Yourls: Add support for postgres

Created on 26 Apr 2017  路  10Comments  路  Source: YOURLS/YOURLS

In addition to MySQL/MariaDB support, the ability to use postgres would be very useful, either through a plugin or through native support.

Most helpful comment

I have YOURLS running on postgres : https://github.com/iWantToKeepAnon/YOURLS

It is a cloned repo with pgsql changes. I have not cleaned it up at all and I did not create it as a plugin. : /

Most of the original SQL is mysql/pgsql compatible once I removed the mysql backtick character. The CREATE TABLE and date/time functions are different and would need abstracting to merge this upstream. But I am content right now to use it and merge upstream changes down into this repo as needed. I'm not sure I have the time or interest to modularize the project, and not sure Ozh would accept such a grand architecture PR anyway.

All 10 comments

At the moment we're using a (super-old-but-it-works) database library that has Postgresql support: @ezSQL

You could quite easily code a plugin to add Postgresql support, just as I did to add SQLite support: https://github.com/ozh/yourls-sqlite

In the future we'll be probably using a more up to date and modern DB library and such support should be even more trivial to add.

@ozh I guess it's better to reply here than open a new issue but please forgive me if I made a mistake. Is there any news about PostgreSQL support? Where can I find further information? I'd like to run my own YOURLS, my other apps use PostgreSQL and I'd like to use it with YOURLS too. Is it possible?

@Attoy current dev (master) now uses PDO to connect to DB engine. I haven't tried yet but from how I have coded stuff, I think a simple plugin should work to connect to a PGSQL server, something like:

<?php
/**
 * the plugin header
 */

yourls_add_filter( 'db_connect_custom_dsn', 'ozh_pgsql_custom' );
function ozh_pgsql_custom($in) {
    $dsn = 'pgsql:host=192.168.13.37;port=5432;dbname=omgwtf';
    return($dsn);
}

Please test & report :)

I have to create a .php file and put it in, for example, /user/plugins/pgsql ?
Then do I need to modify the config.php to point to this file?

Just a plugin.php in /user/plugins/attoy-psql

I added the file as per your instructions however I get this error when I visit the domain.com/admin page:

Fatal error

YOURLS requires the mysql, mysqli or pdo_mysql PHP extension. No extension found. Check your server config, or contact your host.

I actually don't have those extensions as using PSQL I don't need them. Do I need to install them even if I wanna use PSQL?

See if you can override the DB driver in your config, maybe. https://github.com/YOURLS/YOURLS/blob/10a8d986813fb4b90b4aa08cb99356b9cb19c556/includes/functions-http.php#L300-L301

PDO or whatever PSQL's extension name is, whichever you have installed.

(Edited to note that I removed the quoted text from @ozh's email reply. GitHub should be smart enough not to include its own email footers, but apparently it does anyway.)

No, indeed, it's a good call. I'm currently mostly offline because moving
but when I'm back online I'll check that extension problem

Awesome, thank you @ozh !

I have YOURLS running on postgres : https://github.com/iWantToKeepAnon/YOURLS

It is a cloned repo with pgsql changes. I have not cleaned it up at all and I did not create it as a plugin. : /

Most of the original SQL is mysql/pgsql compatible once I removed the mysql backtick character. The CREATE TABLE and date/time functions are different and would need abstracting to merge this upstream. But I am content right now to use it and merge upstream changes down into this repo as needed. I'm not sure I have the time or interest to modularize the project, and not sure Ozh would accept such a grand architecture PR anyway.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schapsl picture schapsl  路  4Comments

ChrisChiera picture ChrisChiera  路  5Comments

uusijani picture uusijani  路  3Comments

sirtet picture sirtet  路  6Comments

wefixit-AT picture wefixit-AT  路  5Comments