Re: Question regarding database.php

2010-02-01 Thread bj204
Thanks to Miles for setting me straight on the constant requirement.

I've followed this lead as far as I can take it and here is what I
think I've learned.

1. In the context of database.php it is not possible to define
constants from the $_SERVER superglobal for non-standard elements,
namely, those which I have defined with SetEnv statements.  When I
reference elements such as NCGE_NEW_DB_HOST, CakePHP gives index out
of range messages.

2. As an alternative I tried using a getenv function such as:

define( 'HOST', getenv('NCGE_NEW_DB_HOST') );

This does not generate errors.  It just returns an empty string for
the constant.

3. When I tested all this in separate scripts, it works fine, so I've
come to the conclusion that, in ways that I don't have the knowledge/
skill to unravel, the environment in which database.php runs is
designed specifically to prevent what I'm trying to do.

The general presumption must be that putting cleartext dbConnect
strings into database.php is the secure and best practice approach.
Any clarification on why this is so would be appreciated, as I've not
been able to find any explanation.  Thanks again.


On Jan 25, 12:53 pm, Miles J mileswjohn...@gmail.com wrote:
 Because you cant use variables or functions within class properties.
 You can only use constants.

 define('HOST', $_SERVER['NCGE_NEW_DB_HOST']);

 'host' = HOST,

 On Jan 25, 6:25 am, bj204 bobj...@gmail.com wrote:

  Okay, let me be more specific in hopes of a response.

  My database.php file contains the following class statement:

  class DATABASE_CONFIG {

          var $default = array(
                  'driver' = 'mysql',
                  'persistent' = false,
                  'host' = $_SERVER['NCGE_NEW_DB_HOST'],
                  'login' = 'xxx',
                  'password' = 'xx',
                  'database' = 'xxx',
                  'prefix' = '',
          );

          var $test = array(
                  'driver' = 'mysql',
                  'persistent' = false,
                  'host' = 'localhost',
                  'login' = 'user',
                  'password' = 'password',
                  'database' = 'test_database_name',
                  'prefix' = '',
          );

  }

  Use of $_SERVER[['NCGE_NEW_DB_HOST'], which is set to localhost,
  produces the error:

  Parse error: parse error, unexpected T_VARIABLE in /var/www/test/soc/
  ncge/app/config/database.php on line 84

  If I define the same $default array elsewhere in a test php program
  and display it with a print_r function, it works fine.

  Why do values from the $_SERVER array fail to resolve in this context
  or is there an obvious syntax error in what I've specified?

  On Jan 23, 10:04 am, bj204 bobj...@gmail.com wrote:

   When configuring database.php, is it possible to assign elements from
   the $_SERVER array (which I have set up to include login, password and
   database name values) to corresponding elements of the $default or
   $test arrays?

   If so, could someone please describe the syntax or other requirements
   for doing this properly.

   I have experimented with many different specifications, some of which
   work without giving syntax errors, but none so far have allowed me to
   connect to a database, whereas just including the actual strings works
   fine.

   Is doing something like this considered good database security
   practice in the CakePHP world, or are there other preferred ways of
   protecting database access information?  As may be obvious, I'm very
   new to this environment.

   Thanks in advance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Question regarding database.php

2010-01-25 Thread bj204
Okay, let me be more specific in hopes of a response.

My database.php file contains the following class statement:

class DATABASE_CONFIG {

var $default = array(
'driver' = 'mysql',
'persistent' = false,
'host' = $_SERVER['NCGE_NEW_DB_HOST'],
'login' = 'xxx',
'password' = 'xx',
'database' = 'xxx',
'prefix' = '',
);

var $test = array(
'driver' = 'mysql',
'persistent' = false,
'host' = 'localhost',
'login' = 'user',
'password' = 'password',
'database' = 'test_database_name',
'prefix' = '',
);
}

Use of $_SERVER[['NCGE_NEW_DB_HOST'], which is set to localhost,
produces the error:

Parse error: parse error, unexpected T_VARIABLE in /var/www/test/soc/
ncge/app/config/database.php on line 84

If I define the same $default array elsewhere in a test php program
and display it with a print_r function, it works fine.

Why do values from the $_SERVER array fail to resolve in this context
or is there an obvious syntax error in what I've specified?

On Jan 23, 10:04 am, bj204 bobj...@gmail.com wrote:
 When configuring database.php, is it possible to assign elements from
 the $_SERVER array (which I have set up to include login, password and
 database name values) to corresponding elements of the $default or
 $test arrays?

 If so, could someone please describe the syntax or other requirements
 for doing this properly.

 I have experimented with many different specifications, some of which
 work without giving syntax errors, but none so far have allowed me to
 connect to a database, whereas just including the actual strings works
 fine.

 Is doing something like this considered good database security
 practice in the CakePHP world, or are there other preferred ways of
 protecting database access information?  As may be obvious, I'm very
 new to this environment.

 Thanks in advance.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en