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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With