Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Biology Forums on May 10, 2019, 10:44:27 AM

Title: Possible to access different database within same server?
Post by: Biology Forums on May 10, 2019, 10:44:27 AM
I'd like to access a table found within another database other than the one stated in my settings.php file. The good thing is that the other database is found on the same server. Are SMF's database functions designed to access other databases, or must I use the database within that chosen in settings.php?
Title: Re: Possible to access different database within same server?
Post by: Illori on May 10, 2019, 10:51:38 AM
if the user that has rights to the SMF database has no rights to the other database it cannot read from it. this is handled on the server level not SMF.
Title: Re: Possible to access different database within same server?
Post by: Biology Forums on May 10, 2019, 10:53:33 AM
I have 2 websites, each one has their own database.

Website 1 wants to access tables in website 2, sort of thing
Title: Re: Possible to access different database within same server?
Post by: SychO on May 10, 2019, 11:10:30 AM
Quote from: Study Force on May 10, 2019, 10:53:33 AM
I have 2 websites, each one has their own database.

Website 1 wants to access tables in website 2, sort of thing

Quote from: Illori on May 10, 2019, 10:51:38 AM
if the user that has rights to the SMF database has no rights to the other database it cannot read from it. this is handled on the server level not SMF.

^
Title: Re: Possible to access different database within same server?
Post by: Kindred on May 10, 2019, 11:56:23 AM
sure - you can do almost anything you want - if you can code it.
However, no - you can not use SMF's database functions to access a different database. SMF's database functions are specifically written as a closed loop - they pre-parse the request, clean it (reject it if its malicious) and then access ONE database, by using ONE user and most of the functions perform ONE action.

this is security.
Title: Re: Possible to access different database within same server?
Post by: Looking on May 10, 2019, 03:12:16 PM
You could call the data from the external table and store it within the DB for SMF using an external script and then have SMF utilize it that way.
Title: Re: Possible to access different database within same server?
Post by: vbgamer45 on May 10, 2019, 04:09:34 PM
I generally do SELECT * FROM databasename.tablename  that will work in smf database calls.
Title: Re: Possible to access different database within same server?
Post by: Biology Forums on May 10, 2019, 05:02:01 PM
Quote from: vbgamer45 on May 10, 2019, 04:09:34 PM
I generally do SELECT * FROM databasename.tablename  that will work in smf database calls.

I'll try that. Or, as mentioned, store the information I need from website B in a JSON file that can then be accessed via URL in website A.
Title: Re: Possible to access different database within same server?
Post by: vbgamer45 on May 10, 2019, 05:18:46 PM
Less overhead doing the sql directly. The mysql user has to have access to both databases.