[MSSQL/HELP] Getting data from 2 diffrent DB
Hi , i wanna get top 50 result from MuOnline database , table Character and Character name , and then MuOnline_Event database , table T_MU2003_EVENT , sort by EventChips which is in T_MU2003_EVENT ... :/
any ideas how to do it?
Human Language :
i want to show Character.Name from table Character from db MuOnline instead of AccountID from table T_MU2003_EVENT from db MuOnline_Event
got any ideas? , all i did for now is
Code:
<?php
mssql_select_db('MuOnline_Event', $conn) or die;
$result = mssql_query("SELECT
TOP 50
AccountID,
(SELECT
$nazwabazy.dbo.Character.Class FROM
$nazwabazy.dbo.Character WHERE
$nazwabazy.dbo.Character.Name COLLATE database_default = T_MU2003_EVENT.AccountID COLLATE database_default) as Class,
EventChips
FROM T_MU2003_EVENT
ORDER BY EventChips DESC") or die;
$nazwabazy = $databasename (polish language ..)
and $nazwabazy is specified in another file , so basically $nazwabazy=MuOnline
i'll buy a beer for the person who will be 1st to help hehe :)
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
PHP Code:
//You could have two connections? It isn't a fast way but I think it should work:P
<?php
$con1 = mssql_connect();
$db1 = mssql_select_db();
$query1 = "";
$fetchit1($query1);
mssql_close($con1);
$con2 = mssql_connect();
$db2 = mssql_select_db();
$query2 = "";
$fetchit2($query2);
mssql_close($con2);
?>
I don't have time too make it complete but with 2 connections you could make it work:)
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
Okay but question , how then i'll use accountID with the same Character?
i mean , it can't display characters randomly .. it needs to be the same as specified in Accounts :p
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
you can use in mysql
Code:
SELECT * FROM database.table
i dunno if you can in mssql
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
select ....
from [databasename].[owner].[table or view name]
will let you select from multiple DBs in a single query. You have to use a 3 part name.
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
Quote:
Originally Posted by
bone-you
select ....
from [databasename].[owner].[table or view name]
will let you select from multiple DBs in a single query. You have to use a 3 part name.
True
You can use this as well:
PHP Code:
SELECT * FROM [db]..[table]
But its same as urs just without owner
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
<?php
mssql_select_db('MuOnline_Event', $conn) or die;
$result = mssql_query("SELECT
TOP 50 Character FROM $nazwabazy.Character,
(SELECT $nazwabazy.dbo.Character.Name FROM $nazwabazy.dbo.Character WHERE T_MU2003_EVENT.AccountID COLLATE database_default = $nazwabazy.dbo.Character.Name COLLATE database_default) as Name,
EventChips
AND ?? FROM T_MU2003_EVENT
ORDER BY EventChips DESC") or die;
oopsie , did something wrong , can some1 correct me? :(
sh*t , it's starting to give me headache :D
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
$nazwabazy.dbo.Character.Name
doesn't make much sense to me
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
Quote:
Originally Posted by
foxx
$nazwabazy.dbo.Character.Name
doesn't make much sense to me
Yeah, where did you defined $nazwabazy ?
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
in other file , don't worry its included
as i've said $nazwabazy = MuOnline , its same thing! :)
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
Code:
mssql_select_db('MuOnline_Event', $conn) or die;
Take that out, you don't want to select a db. You just want to connect to mssql, and run a query, selecting the database & table as you run the query. The reason you select a db is because typically (and preferably) you have all of your data in one db, and it's annoying to write the db and all that in your query each time. So if you don't select a db, it let's you run queries on multiple databases, without disrupting the MsSQL connection.. It's not ideal, but it's what you want. Oh, and the databases need to be on the same server with the same host/user/pass data, obviously.. Otherwise you need to have two separate connections, I guess..
I'd suggest keeping all the data in one single database, and using mssql_select_db('your_db')..
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
aahhh! thanks ;* thats the idea :D im gonna try it and write about results
yeah , i know it ... its just 1 person that is "smart" made a muserver on 3db -.-
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
I think that person has the knowledge for how you could do the things where other people may have problems with:P
I lolled at your location:P
Re: [MSSQL/HELP] Getting data from 2 diffrent DB
You can actually select from another sql server as long as they are linked using host.db.owner.table so the dbs don't even have to be on the same server.