backend_ejabberd_postgres.php

Thu, 13 May 2010 09:31:01 -0500

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 13 May 2010 09:31:01 -0500
changeset 0
472198dc918e
permissions
-rw-r--r--

Initial commit

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

mercurial