How to install multi wordpress blog under one database?

Sometimes we only have one mysql database, and we have several domain names. How to install wordpress for each domain under one database then?

Here is an example, say:   www.eyewearsaver.com, www.opticalsaver.com, www.eyeglassessaver.com, www.eyewearsave.com, and www.glassessaver.com.

First, you should choose one domain name as the main one, say eyewearsaver.com,  and the others redirect to eyewearsaver.com from your webhost cpanel.

Second, install wordpress under www.eyewearsaver.com. After installaction, login FTP, and open config.php. Two places need to be modifed:

First:

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘common databse name here’);

/** MySQL database username */
define(‘DB_USER’, ‘common database user name here’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘common user name password here’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Second, set up different mysql table prefix for each domain name.

// $table_prefix  = ‘wp_’;

$hostname = $_SERVER[‘SERVER_NAME’];
$hostname = str_replace(‘www.’, ”, $hostname);

// switch($_SERVER[‘HTTP_HOST’])
switch($hostname) {
case “opticalsaver.com”:
$table_prefix  = ‘opticalsaver_’;
break;

case “eyeglassessaver.com”:
$table_prefix  = ‘eyeglassessaver_’;
break;

case “eyewearsave.com”:
$table_prefix  = ‘eyewearsave_’;
break;

case “glassessaver.com”:
$table_prefix  = ‘glassessaver_’;
break;

default:
$table_prefix  = ‘eyewearsaver_’;
break;  }

Save and done!