Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
how does jamroom know what database name to use?
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/24/11 23:14 
I am working on V2 of an existing module. In order to preserve the data for anyone installing V2 over V1, I need to check mysql's information_schema for existing tables. In order to do that I need to be able to know the name of the database that jamroom is using. I tried to iterate through the $config array as well as the $GLOBALS array and I was unable to find how jamroom knows which database to use.
Of course I know which database table my copy of jamroom are using but I need to know how jamroom knows. Any advice?

Thanks,
Tim McCune

Back to top
smith.kyle
CodeSmith


Joined: 27 Apr 2006
Posts: 22009
Location: Southern California

Posted: 09/25/11 13:47 
Jamroom does everything automatically in the dbQuery function - if you don't want it to use the jamroom tables you'll want to use the regular mysql functions.

Kyle


_________________
kyle[at]jamroom.net

Yes...that's a soda machine...

I get bored when no one's posting...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/26/11 16:57 
its $jamroom_db that you want.

When you setup your module, usually in the includes.php file you will add to the $jamroom_db array with your modules database names.

with a line something like this.

Code
// set up our custom database tables
$jamroom_db['apLaunch_nukes'] = $config['db_prefix'].'apLaunch_nukes'; //holds the secret firing codes.



Then you will get something like this in $jamroom_db jamroom_apLaunch_nukes

to use it
$sql = "SELECT * FROM {$jamroom_db['apLaunch_nukes']} WHERE target = $target";

Is that useful?


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/27/11 13:24 
Thanks for the response. Essentially my plan was to query the the information_schema table for the existence of my modules tables, by doing the following query within the schema.php file:

Code

SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = '[jamroom database]'
AND table_name = 'mcAds';


And if the table exists, I need to test to see if a specific column(s) exists (Which is used in the modules V1.x but not V2.x) And if the column(s) exist I will rename the table with a temp name. Then let the schema.php script to perform the regular table verification by running the dbVerifyTable().

Then after all the new table schemas are in place, I plan to check the database for the existence of the renamed tables, and if they exist, migrate the appropriate data over to the new tables. Then delete temporary tables. As far as I understand, the $jamroom_db[] array contains the names of the database table names but not the actual name of the database, but I haven't checked yet.

After a little digging, I found where the database connection is created and placed into the $GLOBBALS array but I never found where the actual database name was found. I could just assume that the database name is jamroom but that would only be the case for people who use the default settings during installation.

Thanks,
Tim McCune

Back to top
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/27/11 14:49 
Found what I was looking for. After examining jamroom-database.inc.php I found that the connection is made using: $GLOBALS['JR_HTPASSWD'][1] to hold the name of the database name.


Thanks for the help,
Tim

Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.