I’ve received a request to modify some pages of a website which is based on Drupal. Unfortunately, I hear about Drupal so many times but I don’t have any experience about it at all.
After download all current source files and database to my staging, I spent half of hour to find out where do I re configure the database settings as it’s not the same with the live settings.
In this article, I would like to take note it because I don’t want to spend another half of hour to find it again in a near future and it may save someone time, hopefully.
Database Configuration Settings In Drupal
It’s located at drupal/sites/default/settings.php similar with below:
[text highlight=”48″] /*** Database settings:
*
* Note that the $db_url variable gets parsed using PHP’s built-in
* URL parser (i.e. using the "parse_url()" function) so make sure
* not to confuse the parser. If your username, password
* or database name contain characters used to delineate
* $db_url parts, you can escape them via URI hex encodings:
*
* : = %3a / = %2f @ = %40
* + = %2b ( = %28 ) = %29
* ? = %3f = = %3d & = %26
*
* To specify multiple connections to be used in your site (i.e. for
* complex custom modules) you can also specify an associative array
* of $db_url variables with the ‘default’ element used until otherwise
* requested.
*
* You can optionally set prefixes for some or all database table names
* by using the $db_prefix setting. If a prefix is specified, the table
* name will be prepended with its value. Be sure to use valid database
* characters only, usually alphanumeric and underscore. If no prefixes
* are desired, leave it as an empty string ”.
*
* To have all database names prefixed, set $db_prefix as a string:
*
* $db_prefix = ‘main_’;
*
* To provide prefixes for specific tables, set $db_prefix as an array.
* The array’s keys are the table names and the values are the prefixes.
* The ‘default’ element holds the prefix for any tables not specified
* elsewhere in the array. Example:
*
* $db_prefix = array(
* ‘default’ => ‘main_’,
* ‘users’ => ‘shared_’,
* ‘sessions’ => ‘shared_’,
* ‘role’ => ‘shared_’,
* ‘authmap’ => ‘shared_’,
* );
*
* Database URL format:
* $db_url = ‘mysql://username:[email protected]/databasename’;
* $db_url = ‘mysqli://username:[email protected]/databasename’;
* $db_url = ‘pgsql://username:[email protected]/databasename’;
*/
$db_url = ‘mysqli://db-user:[email protected]/db-name’;
$db_prefix = ”;
[/text]
Or in the current of Drupal (7.7):
[text highlight=”30,31,32,33″] * Database configuration format:* @code
* $databases[‘default’][‘default’] = array(
* ‘driver’ => ‘mysql’,
* ‘database’ => ‘databasename’,
* ‘username’ => ‘username’,
* ‘password’ => ‘password’,
* ‘host’ => ‘localhost’,
* ‘prefix’ => ”,
* );
* $databases[‘default’][‘default’] = array(
* ‘driver’ => ‘pgsql’,
* ‘database’ => ‘databasename’,
* ‘username’ => ‘username’,
* ‘password’ => ‘password’,
* ‘host’ => ‘localhost’,
* ‘prefix’ => ”,
* );
* $databases[‘default’][‘default’] = array(
* ‘driver’ => ‘sqlite’,
* ‘database’ => ‘/path/to/databasefilename’,
* );
* @endcode
*/
$databases = array (
‘default’ =>
array (
‘default’ =>
array (
‘database’ => ‘drupal77’,
‘username’ => ‘root’,
‘password’ => ”,
‘host’ => ‘localhost’,
‘port’ => ”,
‘driver’ => ‘mysql’,
‘prefix’ => ”,
),
),
);
[/text]