backend_ejabberd_postgres.php

changeset 0
472198dc918e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend_ejabberd_postgres.php	Thu May 13 09:31:01 2010 -0500
@@ -0,0 +1,40 @@
+<?php
+
+Class RegistrationBackend {
+
+	protected $dbconn;
+	
+	function init($config)
+	{
+		$this->dbconn = pg_connect("host={$config['dbhost']} dbname={$config['dbname']}\
+			 user={$config['dbuser']} password={$config['dbpass']}")
+		    or die('Could not connect: ' . pg_last_error());
+	}
+
+	function validate($user, $pass)
+	{
+		return FALSE;
+	}
+	
+	function exists($user)
+	{
+		$result = pg_query_params('SELECT * FROM users WHERE username = $1 LIMIT 1',
+			array($user));
+		if (pg_num_rows($result) > 0 )
+			return TRUE;
+		return FALSE;
+	}
+	
+	function create($user, $pass)
+	{
+		return pg_query_params('INSERT INTO users ("username", "password") VALUES($1, $2)',
+			array($user, $pass));
+	}
+	
+	function close()
+	{
+		pg_close($this->dbconn);
+	}
+}	
+
+?>

mercurial