Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect to sql "server group" with php to run query over multiple databases

I am trying to connect to an MSSQL Server group with PHP and action a select query over a view . I can connect & pull results from the server . I can connect & pull results from a DB

With MSSQL under registered servers (top left) you can create a new server group and add existing databases as a server registration this allows for a single query to be run over multiple databases. I cant find any information on how to connect to this from PHP.

FYI:-Setting Server Group: https://www.youtube.com/watch?v=bTz3OZKTdMg

I have also tried creating a view in each database then in one database creating a view that joins each of the views together it works in management studio but i get an error form PHP "Undefined Index"

I.e db1:

Create View ffa

db2:

Create view ffa

:dblook

create view ffa as select * From db1.ffa union all select * From db2.ffa

Then php to look at dblook.ffa I get a connection but "Undefined Index" error?

I have both SQL and Express currently testing on Express I would prefer the connecting to server group option (seems a lot faster in management studio) But happy to try any other solution

like image 906
benaw Avatar asked Apr 04 '13 05:04

benaw


People also ask

How do I run the same query on multiple databases in SQL Server?

There is a handy undocumented stored procedure that allows you to do this without needing to set up a cursor against your sysdatabases table in the master database. This can be done by using sp_MSforeachdb to run the same command in all databases.

How do I run a SQL script against multiple databases?

To run a single script against multiple databases, you'll need to create a list of databases. Then iterate through each one and fire a USE command and then the command itself.

Is it possible to connect to multiple databases?

Many database management and development tools support multiple connections to homogeneous databases, i.e., where they are all of the same type, ALL MySQL, ALL SQL Server, ALL Oracle, etc.


1 Answers

The server group is just a logical way to group Servers in the GUI. It's not a function of the SQL Server database engine.

What you are referring to is partitioned views which falls under the concept of Federated Database Servers.

  • Federated Databases
  • Partitioned Views
  • Linked Servers

Basically, using Linked Servers, you create views on each database servers that union multiple servers together. A load balancer can then point to any database server. This only happens on the read requests as other CRUD operations require some type of routing.

like image 68
Chris H Avatar answered Oct 07 '22 15:10

Chris H