Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6788155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:27:05+00:00 2026-05-26T17:27:05+00:00

<?php class DATABASE_CONFIG { public $default = array( ‘datasource’ => ‘Database/Mysql’, ‘persistent’ => false,

  • 0
<?php
class DATABASE_CONFIG {
    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'hostname',
        'login' => 'username',
        'password' => 'password',
        'database' => 'database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
    );
    public $test = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'hostname',
        'login' => 'username',
        'password' => 'password',
        'database' => 'database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
    );
}

There are some default value in login,password and database. How can i write a script to edit the login,password and database ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:27:06+00:00Added an answer on May 26, 2026 at 5:27 pm

    php file contains your example text:

    kent$  awk '/login/{l++;if(l>1)gsub(/root/,"newLogin");} 
            /password/{p++;if(p>1)gsub(/xxx/,"newPwd");} 
            /database/{d++;if(d>1)gsub(/xxx/,"newDB");} 1' php
    <?php
    class DATABASE_CONFIG {
    
        public $default = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'root',
            'password' => 'xxx',
            'database' => 'xxx',
            'prefix' => '',
            //'encoding' => 'utf8',
        );
    
        public $test = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'newLogin',
            'password' => 'newPwd',
            'database' => 'cake_test_db',
            'prefix' => '',
            //'encoding' => 'utf8',
        );
    }
    

    this only changes the blocks after your $default block. and, only default value will be changed. e.g. in your $test, 'database' => 'cake_test_db' the value is not the default ‘xxx’, so it would not be changed.

    if you like you can put new value in variable, and passing to awk with -v.

    edit

    if you want to change all values, (including $default block), it would be easier, check the lines below: (same as above, only defalut values (root, xxx,xxx) would be changed.

    kent$    awk '/login/{gsub(/root/,"newLogin");}                                                                                          
                /password/{gsub(/xxx/,"newPwd");}                                                                                            
                /database/{gsub(/xxx/,"newDB");} 1' php                                                                                      
    <?php
    class DATABASE_CONFIG {
    
        public $default = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'newLogin',
            'password' => 'newPwd',
            'database' => 'newDB',
            'prefix' => '',
            //'encoding' => 'utf8',
        );
    
        public $test = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'login' => 'newLogin',
            'password' => 'newPwd',
            'database' => 'cake_test_db',
            'prefix' => '',
            //'encoding' => 'utf8',
        );
    }
    

    edit2

    this works for your new example in question.

     sed '/login/{s/username/newLOGIN/}; /password/{s/password/newPWD/2}; /database/{s/database_name/newDB/}' php
    
        <?php
        class DATABASE_CONFIG {
            public $default = array(
                'datasource' => 'Database/Mysql',
                'persistent' => false,
                'host' => 'hostname',
                'login' => 'newLOGIN',
                'password' => 'newPWD',
                'database' => 'newDB',
                'prefix' => '',
                //'encoding' => 'utf8',
            );
            public $test = array(
                'datasource' => 'Database/Mysql',
                'persistent' => false,
                'host' => 'hostname',
                'login' => 'newLOGIN',
                'password' => 'newPWD',
                'database' => 'newDB',
                'prefix' => '',
                //'encoding' => 'utf8',
            );
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the one I'm using: <?php final class Database { private static $oDb; public
I am using a PHP class for login purposes. The MySQL database that the
I was writing a database handler class in PHP using the mysqli class and
at my working place (php only) we have a base class for database abstraction.
PHP/MySQLisolating database access in class - how to handle multiple row Selects Here’s a
I have a PHP class that stores a complex multidimensional array, and rather than
I have a MySQL singleton class written in PHP. Its code is listed below:
from http://www.php.net/manual/en/class.pdo.php ###### config.ini ###### db_driver=mysql db_user=root db_password=924892xp [dsn] host=localhost port=3306 dbname=localhost [db_options] PDO::MYSQL_ATTR_INIT_COMMAND=set
from http://www.php.net/manual/en/class.pdo.php ###### config.ini ###### db_driver=mysql db_user=root db_password=924892xp [dsn] host=localhost port=3306 dbname=localhost [db_options] PDO::MYSQL_ATTR_INIT_COMMAND=set
I'm retrieving information about resources from a MySQL database using PHP. The information about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.