| 1 | <?php |
| 2 | |
| 3 | Class RegistrationBackend { |
| 4 | |
| 5 | protected $dbconn; |
| 6 | |
| 7 | function init($config) |
| 8 | { |
| 9 | $this->dbconn = pg_connect("host={$config['dbhost']} dbname={$config['dbname']}\ |
| 10 | user={$config['dbuser']} password={$config['dbpass']}") |
| 11 | or die('Could not connect: ' . pg_last_error()); |
| 12 | } |
| 13 | |
| 14 | function validate($user, $pass) |
| 15 | { |
| 16 | return FALSE; |
| 17 | } |
| 18 | |
| 19 | function exists($user) |
| 20 | { |
| 21 | $result = pg_query_params('SELECT * FROM users WHERE username = $1 LIMIT 1', |
| 22 | array($user)); |
| 23 | if (pg_num_rows($result) > 0 ) |
| 24 | return TRUE; |
| 25 | return FALSE; |
| 26 | } |
| 27 | |
| 28 | function create($user, $pass) |
| 29 | { |
| 30 | return pg_query_params('INSERT INTO users ("username", "password") VALUES($1, $2)', |
| 31 | array($user, $pass)); |
| 32 | } |
| 33 | |
| 34 | function close() |
| 35 | { |
| 36 | pg_close($this->dbconn); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | ?> |