cvs: pear /Config README.Config

From: Date: Wed, 24 Jul 2002 11:24:37 +0000
Subject: cvs: pear /Config README.Config
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5322@lists.php.net to get a copy of this message
mansion Wed Jul 24 07:24:37 2002 EDT Modified files: /pear/Config README.Config Log: Added info about the new features in the db container. Index: pear/Config/README.Config diff -u pear/Config/README.Config:1.4 pear/Config/README.Config:1.5 --- pear/Config/README.Config:1.4 Tue May 7 13:10:55 2002 +++ pear/Config/README.Config Wed Jul 24 07:24:36 2002 @@ -1,7 +1,7 @@ Documentation and Tutorial for PEAR-Config by Alexander Merz -$Id: README.Config,v 1.4 2002/05/07 17:10:55 rashid Exp $ +$Id: README.Config,v 1.5 2002/07/24 11:24:36 mansion Exp $ A first example @@ -319,15 +319,26 @@ xml files can be written in different ways meaning almost the same, it's hard to preserve the old format. But it's certainly possible.. +-------------------------------------------------------------------------------- DB -you can store you're config data also in a Database. This implementation uses -the Pear::DB Classes, so any Database supported within pear should be supported -here also. +The Config class allows you to store your configuration data in a database. +It uses PEAR DB wrapper, so every database supported by PEAR DB are also +supported by the Config class. + +Upon construction, you can define how your configuration table will look like by +using an array of options like this: + +$options['blockcol'] = 'block'; // column for block info +$options['datasrccol'] = 'datasrc'; // column for datasrc info +$options['namecol'] = 'name'; // column for parameter +$options['valuecol'] = 'value'; // column for value +$options['table'] = 'config'; // configuration table +$options['dsn'] = "$dbtype://$user:$pass@$host/$dbname"; // dsn -the table in the Database has to look the following way (the length of the -varchar does not matter and additional fields can be included.) +This way, you can use any table like this: +# Change field types to what you need CREATE TABLE config ( datasrc varchar(50) NOT NULL, block varchar(50) NOT NULL, @@ -335,29 +346,32 @@ value varchar(50) NOT NULL ); -Calling the constructor: +These two examples use the default settings. Feel free to adapt this settings to +your own application needs. -$conf = new Config("db","mysql://username:password@localhost/dbname") ; +Now, in the constructor, you can pass the options array so that the class knows where to find your configuration information: -the second parameter is the dsn, as described in the pear-db documentation. +$conf = new Config('db', $options) ; -The rest is quite the same as in the IniFile-Implementation. Just try to replace -the constructor-line in the examples for the IniFile-Container and the rest -should work. +Instead of using an array, you could have passed a dsn string or a db object to +the constructor which would have then used the default settings for the table +and column names. If you prefer, you can pass these infos (table and column +names) in an array to the parseInput() method, later on. Nevertheless, the dsn has to be passed to the constructor. -datasrc: it's the equivalent to the filename. so you can have different "ini-files" in the same db-table (for example to store different settings for different users) - -block/name/value: has the same meaning as in the IniFile-Container. +The rest is the same as in the IniFile implementation. +datasrc: + has the same purpose as the filename, so you can have different + ini files in the same database table (for example to store + different settings for different users) +block/name/value: + have the same purpose as in the IniFile Container. Writing back the data is also supported. -Sub-blocks are not supported. - -Options: +Sub-blocks are not supported yet. +-------------------------------------------------------------------------------- -Table [config] The name of the db-table, where the keys/values/etc are - stored. API-Reference

« previous php.pear.cvs (#5322) next »