Not logged in. · Lost password · Register
Forum: General Help and Support Installation and Configuration RSS
Looking for authPDO usage example
Avatar
sTeamTraen #1
Member since Sep 2009 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: Looking for authPDO usage example
I am moving from PHP 5.6 to PHP 7.2 and apparently I can't use authmysql any more. I have been told that authPDO is the best way to connect to my (MySQL) user authentication database. However, I'm having trouble finding what to do.

At the moment, everything I need is in a few lines in local.php:

$conf['plugin']['authmysql']['server'] = '10.x.x.x';
$conf['plugin']['authmysql']['user'] = 'DWUsers';
$conf['plugin']['authmysql']['password'] = 'xxxxxxxx';
$conf['plugin']['authmysql']['database'] = 'DWUsers';

All I want to do is to have this authentication continue to work. But I don't understand the documentation that I have seen for authPDO (e.g., https://www.dokuwiki.org/plugin:authpdo). It talks about writing SQL statements (which I know how to do), but not where to put them, or whether I have to include them directly in an SQL file or call them from PHP, etc etc.

Does someone perhaps have a working example of a simple authPDO configuration so that I know what files to edit and what syntax to use in there? Or experience of migrating from authpysql to authPDO?

Thanks...

Nick
Avatar
schplurtz (Moderator) #2
Member since Nov 2009 · 459 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Hi,

but not where to put them, or whether I have to include them directly in an SQL file or call them from PHP, etc etc.
Just write the SQL statements in conf/local.php. anytime you read option foo on https://www.dokuwiki.org/plugin:authpdo you need to write it as $conf['plugin']['authpdo']['foo']

$conf['plugin']['authmysql']['server'] = '10.x.x.x';
$conf['plugin']['authmysql']['user'] = 'DWUsers';
$conf['plugin']['authmysql']['password'] = 'xxxxxxxx';
$conf['plugin']['authmysql']['database'] = 'DWUsers';
It becomes something like this (check charset) :
  1. $conf['plugin']['authpdo']['debug']='1'; // turn off when everything works
  2. $conf['plugin']['authpdo']['dsn']='mysql:host=10.x.x.x;dbname=DWUsers;charset=utf8';
  3. $conf['plugin']['authpdo']['user']='DWUsers';
  4. $conf['plugin']['authpdo']['pass']='xxxxxxxx';

Given the example database in https://www.dokuwiki.org/plugin:authmysql#example_database, you could add something like this :
  1. $conf['plugin']['authpdo']['select-user']='
  2. SELECT  login    AS user
  3.        ,fullname AS name
  4.        ,pass     AS hash
  5.        ,mail
  6.        ,uid
  7.   FROM users
  8.   WHERE login = :user
  9. ';
  10.  
  11. // untested but should work
  12. $conf['plugin']['authpdo']['select-user-groups']='
  13. SELECT groups.name AS `group`
  14.   FROM usergroup JOIN groups
  15.        ON usergroup.gid = groups.gid
  16.   WHERE usergroup.uid = :uid
  17. ';
This post was edited on 2018-11-05, 10:45 by schplurtz.
Avatar
sTeamTraen #3
Member since Sep 2009 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thanks! That seems to be working. (Your untested code for the groups worked once I put `` characters around the word "group", which was otherwise being treated as a keyword.)
Avatar
schplurtz (Moderator) #4
Member since Nov 2009 · 459 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Thanks for your feedback. I fixed the example.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-08-21, 07:22:16 (UTC +02:00)