phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.db.inc.php,1.16


From: skwashd
Subject: [Phpgroupware-cvs] phpgwapi/inc class.db.inc.php,1.16
Date: Sun, 15 May 2005 13:14:00 +0200

Update of phpgwapi/inc

Modified Files:
     Branch: MAIN
            class.db.inc.php lines: +91 -44

Log Message:
tidy up formatting, readd create_database - needed by setup

====================================================
Index: phpgwapi/inc/class.db.inc.php
diff -u phpgwapi/inc/class.db.inc.php:1.15 phpgwapi/inc/class.db.inc.php:1.16
--- phpgwapi/inc/class.db.inc.php:1.15  Wed May  4 14:42:49 2005
+++ phpgwapi/inc/class.db.inc.php       Sun May 15 11:14:21 2005
@@ -19,7 +19,7 @@
        /**
        * Include concrete database implementation
        */
-       include(PHPGW_API_INC.'/adodb/adodb.inc.php');
+       require_once(PHPGW_API_INC . '/adodb/adodb.inc.php');

        /**
        * Database abstraction class to allow phpGroupWare to use multiple 
database backends
@@ -327,7 +327,8 @@
                * @return boolean True if sucessful, False if fails
                */
                function transaction_abort()
-               {echo "depricated: transaction_abort";
+               {
+                       echo "depricated: transaction_abort";
                        return True;
                }

@@ -402,7 +403,9 @@
                */

                function num_fields()
-               {echo "depricated: num_fields";}
+               {
+                       echo "depricated: num_fields";
+               }

                /**
                * Short hand for num_rows()
@@ -410,7 +413,8 @@
                * @see num_rows()
                */
                function nf()
-               {echo "depricated: nf";
+               {
+                       echo "depricated: nf";
                        return $this->num_rows();
                }

@@ -418,7 +422,8 @@
                * Short hand for print @see num_rows
                */
                function np()
-               {echo "depricated: np";
+               {
+                       echo "depricated: np";
                        print $this->num_rows();
                }

@@ -453,7 +458,7 @@
                */
                function p($Name, $strip_slashes = True)
                {
-                                               echo "depi: p";
+                       echo "depi: p";
                        print $this->f($Name, $strip_slashes);
                }

@@ -464,7 +469,9 @@
                * @return integer sequence id
                */
                function nextid($seq_name)
-               {                       echo "depi: nextid";}
+               {
+                       echo "depi: nextid";
+               }

                /**
                * Get description of a table
@@ -475,7 +482,7 @@
                */
                function metadata($table = '',$full = false)
                {
-                                               echo "depi: metadata";
+                       echo "depi: metadata";
                        /*
                         * Due to compatibility problems with Table we changed 
the behavior
                         * of metadata();
@@ -512,16 +519,24 @@
                */
                function halt($msg, $line = '', $file = '')
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: halt";}
-
-               /**
+                       if($this->debug)
+                       {
+                               echo "depricated: halt";
+                       }
+               }
+
+               /**
                * Get a list of table names in the current database
                *
                * @return array list of the tables
                */
                function table_names()
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: table_names";
+                       if($this->debug)
+                       {
+                               echo "depricated: table_names";
+                       }
+
                        if(!$this->adodb->IsConnected())
                        {
                                $this->connect();
@@ -536,7 +551,7 @@
                */
                function index_names()
                {
-                                               echo "depi: index_names";
+                       echo "depi: index_names";
                        return array();
                }

@@ -545,44 +560,76 @@
                *
                * @param string $adminname Name of database administrator user 
(optional)
                * @param string $adminpasswd Password for the database 
administrator user (optional)
+               * @returns bool was the new db created?
                */
                function create_database($adminname = '', $adminpasswd = '')
-               {                       echo "depi: create_database";}
+               {
+                       //THIS IS CALLED BY SETUP DON'T KILL IT!
+                       if ( $this->adodb->IsConnected() )
+                       {
+                               $this->adodb->Disconnect(); //close the dead 
connection to be safe
+                       }
+
+                       $this->adodb = 
NewADOConnection($GLOBALS['phpgw_info']['server']['db_type']);
+                       $this->adodb->NConnect($this->Host, $adminname, 
$adminpasswd);
+
+                       if ( !$this->adodb->IsConnected() )
+                       {
+                               echo 'Connection FAILED<br />';
+                               return False;
+                       }
+
+                       //create the db
+                       $this->adodb->Execute("CREATE DATABASE 
{$this->Database}");
+
+                       //Grant rights on the db
+                       switch ($GLOBALS['phpgw_info']['server']['db_type'])
+                       {
+                               case 'mysql':
+                                       $this->adodb->Execute("GRANT ALL ON 
{$this->Database}.*"
+                                                       . " TO 
{$this->address@hidden'SERVER_NAME']}"
+                                                       . " IDENTIFIED BY 
'{$this->Password}'");
+                               default:
+                                       //do nothing
+                       }
+                       $this->adodb->Disconnect();
+                       return True;
+               }


-       /**
-                * Prepare SQL statement
-                *
-                * @param string $query SQL query
-                * @return integer|boolean Result identifier for 
query_prepared_statement() or FALSE
-                * @see query_prepared_statement()
-                */
+               /**
+               * Prepare SQL statement
+               *
+               * @param string $query SQL query
+               * @return integer|boolean Result identifier for 
query_prepared_statement() or FALSE
+               * @see query_prepared_statement()
+               */
                function prepare_sql_statement($query)
                {
-                                               echo "depi";
-                 if (($query == '') || (!$this->connect()))
-                  {
-                       return(FALSE);
-                  }
-                 return(FALSE);
+                       echo "depi";
+                       if (($query == '') || (!$this->connect()))
+                       {
+                               return false;
+                       }
+                       return false;
                }

-        /**
-         * Execute prepared SQL statement
-         *
-         * @param resource $result_id Result identifier from 
prepare_sql_statement()
-         * @param array $parameters_array Parameters for the prepared SQL 
statement
-         * @return boolean TRUE on success or FALSE on failure
-         * @see prepare_sql_statement()
-         */
-        function query_prepared_statement($result_id, $parameters_array)
-         {
-                 if ((!$this->connect()) || (!$result_id))
-                  {
+               /**
+                * Execute prepared SQL statement
+                *
+                * @param resource $result_id Result identifier from 
prepare_sql_statement()
+                * @param array $parameters_array Parameters for the prepared 
SQL statement
+                * @return boolean TRUE on success or FALSE on failure
+                * @see prepare_sql_statement()
+                */
+               function query_prepared_statement($result_id, $parameters_array)
+               {
+                       if ((!$this->connect()) || (!$result_id))
+                       {
+                               return(FALSE);
+                       }
                        return(FALSE);
-                  }
-                 return(FALSE);
-         }
-
+               }
+
        }
 ?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]