From 0c41c058d10313883f4a08353233deae76e9af92 Mon Sep 17 00:00:00 2001 From: seek3r Date: Fri, 1 Jun 2001 08:57:52 +0000 Subject: [PATCH] added the final steps needed for creating the database for the user --- phpgwapi/inc/class.db_mysql.inc.php | 24 +++++++++++++++++++++++- phpgwapi/inc/class.db_pgsql.inc.php | 25 ++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/phpgwapi/inc/class.db_mysql.inc.php b/phpgwapi/inc/class.db_mysql.inc.php index 94fb602683..84b1af72f5 100644 --- a/phpgwapi/inc/class.db_mysql.inc.php +++ b/phpgwapi/inc/class.db_mysql.inc.php @@ -75,7 +75,6 @@ class db { /* establish connection, select database */ if ( 0 == $this->Link_ID ) { - $this->Link_ID=mysql_pconnect($Host, $User, $Password); if (!$this->Link_ID) { $this->halt("pconnect($Host, $User, \$Password) failed."); @@ -443,4 +442,27 @@ class db { } return $return; } + + function create_database($dbname, $adminname = "", $adminpasswd = "") { + $currentUser = $this->User; + $currentPassword = $this->Password; + $currentDatabase = $this->Database; + + if ($adminname != "") + { + $this->User = $adminname; + $this->Password = $adminpasswd; + $this->Database = "mysql"; + } + $this->disconnect(); + $this->query("CREATE DATABASE $dbname"); + $this->query("grant all on $dbname.* to $currentUser@localhost identified by '$currentPassword'"); + $this->disconnect(); + + $this->User = $currentUser; + $this->Password = $currentPassword; + $this->Database = $currentDatabase; + $this->connect(); + //return $return; + } } diff --git a/phpgwapi/inc/class.db_pgsql.inc.php b/phpgwapi/inc/class.db_pgsql.inc.php index edc723bec4..379ce699f6 100644 --- a/phpgwapi/inc/class.db_pgsql.inc.php +++ b/phpgwapi/inc/class.db_pgsql.inc.php @@ -321,4 +321,27 @@ class db { } return $return; } -} + + function create_database($dbname, $adminname = "", $adminpasswd = "") { + $currentUser = $this->User; + $currentPassword = $this->Password; + $currentDatabase = $this->Database; + + if ($adminname != "") + { + $this->User = $adminname; + $this->Password = $adminpasswd; + $this->Database = "mysql"; + } + $this->disconnect(); + $this->query("CREATE DATABASE $dbname"); + $this->query("grant all on $dbname.* to $currentUser@localhost identified by '$currentPassword'"); + $this->disconnect(); + + $this->User = $currentUser; + $this->Password = $currentPassword; + $this->Database = $currentDatabase; + $this->connect(); + //return $return; + } +} \ No newline at end of file