Adding Databases

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
206
Points
28
Mysidian Dollar
11,706
Is there any way to add databases, not tables, but whole entire databases? My hosting company limits my database size, and this will be a problem as the site grows, even with premium service which would give me unlimited amount of databases. I suppose transfering to a more expensive server option would do the trick, but as I'm a hobbyist right now with no way to pay for that, regular hosting is all I can afford at the moment. I like my company because it is very in-expensive and a green hosting company, plus I'm familiar with their tools.
 
umm it is possible, the database class is not singleton so you can instantiate as many database objects as you want.
 
OK thanks, sorry, I am not an expert in these things. I'll have to look up how to do this
 
Well it is not difficult to instantiate database object, here is how the current database connection is carried out:

PHP:
try{
  $adopts = new Database(DBNAME, DBHOST, DBUSER, DBPASS, PREFIX);
}
catch(PDOException $pe){
  die("Could not connect to database, the following error has occurred: <br><b>{$pe->getmessage()}</b>");  
}

The database object accepts five arguments in its constructor, the database name, host, username, password and prefix. You can instantiate as many database objects as you wish by using this syntax below, which assumes that the database name differs but everything else remains the same

PHP:
$db1 = new Database(DBNAME1, DBHOST, DBUSER, DBPASS, PREFIX);
$db2 = new Database(DBNAME2, DBHOST, DBUSER, DBPASS, PREFIX);
...

Hope this helps.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,119
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top