Connecting To Multiple Databases With Sqlsrv_connect?

May 7, 2011

Basically at the moment I can connect to one database at a time. The thing is the data that I am querying is from multiple website (all starting with V1_database.....). For example my database include V1_database_newyork or V1_database_denver etc.

I have created a query like this in Microsoft SQL Server Management Studio which picks up all the database beginning with V1_database:

FROM sys.databases
WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb') AND name LIKE 'V1_database%'

My current code to connect to one of my databases is as follows (this works fine):

/*data base connection */
$serverName = ".SQLEXPRESS";
$connectionOptions = array("Database"=>"V1_database_newyork",


View 1 Replies


Connecting To Multiple Databases?

I am using sphinx for a site search and it works great but now I am trying to connect to 2 mysql databases with the same exact structure and db2 is a continuance of db1 so all info should flow smoothly. I can easily get the results by switching the db name in the code but how can I select both at once?

here is some code im using

$CONF['sphinx_host'] = 'localhost';
$CONF['sphinx_port'] = 9312;
$CONF['mysql_host'] = "localhost";
$CONF['mysql_username'] = "user";


This code works fine if i enter a single mysql db into $CONF['mysql_database'] = "db1"; but I need to select from db1 and db2. Does anyone know how I can achieve this? Also I did not post the query because I don't think it is very useful it is just a simple select query and I am sure you get the idea.

View 1 Replies

Wordpress - Connecting To Multiple Databases?

I have various websites. 2 or 3 utilize wordpress as a CMS, and use the ExecPHP plugin to execute my PHP content. The others do not use any CMS. I want to setup a system such that a user can register on any ONE site, and that registration is valid for every site in my network.

My idea was a separate database for user information. I could then switch between each sites database and the 'users' database. This is extremely complicated with wordpress however, as I cannot go through and change every wordpress query to include the database which it is querying.

View 5 Replies

Zend Framework : Connecting To Multiple Databases One At A Time?

The problem I am having now is that when I get to the next database, its still selecting from the first database and not the new one.Is it possible to close a connection and then open a new connection while running a script. Remember this is just a script I have no bootstrap set. I just setup a autoload to that I can load my models.While looping through sections of the ini

try {
$db = Zend_Db::factory($section->database->type, $section->database->toArray());


View 1 Replies

PHP & MySQL - Connecting Two Databases

I am trying to understand the best way to extract a list of users from a
table based upon their location.

To do this I have a table containing all the UK postcodes with a grid
reference x & y.
postcode x y
AB10 392900 804900
AB11 394500 805300
AB12 393300 801100
AB13 385600 801900
AB14 383600 801100
AB15 390000 805300
AB16 390600 807800
AB21 387900 813200
AB22 392800 810700
AB23 394700 813500
AB25 393200 806900
AB30 370900 772900

In a seperate table I have a list of users including a postcode.
id firstname postcode
1 Heather BH4
2 Vicky OL1
3 Paola CF8
4 Joanna W14
5 Steve BD13
6 Sally NN1

In short I would like your opinoin on how best (most efficiently) to
calculate the nearest 20 users. The method I am using to calculate the
distance between the users and any chosen postcode is good old Pythagoras
dist = sq root ( (userX * userX) + (userY * userY) - (locationX * locationX)
+ (locationY * locationY) )

It seems that looping through the users to first calculate the distance is
essential. After that point I am not sure about the besr way to proceed.
Do I write the results to a temp table (with distances) then call them in
order of distance or is there a better way?

View 4 Replies

Connecting To Two Databases Simultaneously

Below is the connection info for connecting to two databases simultaneously. When querying the first database, the SQL Query does not connect since it defaults to the second DB. Code:

View 1 Replies

Mysql Connecting To Two Databases

can mysql_query() check where resource link to be used? if 2 server in one host/mechine is not problem. but if we have 2 server in difference location and we want to join in just one query. your code cannot run. because last connection just used..

View 1 Replies

Connecting To Two Databases At The Same Time.

I have the following:

function List($db, $zip = false) {


$town = $db->getRow("SELECT * FROM towns_zipcodes, towns WHERE = '$zip' AND towns_zipcodes.town_id = AND = towns_zipcodes.towns_id AND = LIMIT 1");

return $town;

The page this is for is connected to database1, but I need to query databse2 to get these results. What is the correct way to query another database while connected to database1?

View 5 Replies

Connecting To Two (2) Databases At The Same Time?

What if i have 2 databases, db1 and db2. i want to read raw data from db1 and match it's content with data from db2, then produce some information. How can i do it at the same time? I know that to be able to access mysql data, we have to use the mysql_connect() and mysql_select_db(). mysql_select_db() only allows to connect to single database. what should i do?

View 2 Replies

Connecting To Databases IF Statement?

wondering how i would go about including two connection files...I'm working on a project for university and i have to switch between connecting to my apache server and the university server. I want to make it so that the webpage connects to the correct database for which server its on... rather than having to constantly update 10 of my files to include connection2 rather than connection 1.

View 2 Replies

Query On Two Databases On Two Servers Not Connecting?

I have followed a lot of examples on this issue but I just cannot seem to get this to work. I can query the databases individually with success, but not the two in the same query.

I've tried aliasing, referring to the servers in the query... putting `` around the names etc. Nothing works.

So this is my code

Connection strings:

$databaseprefix = "w-";
$mysqlHost = 'localhost';
$mysqlUser = 'web123-USER1';


Both join fields are INT datatypes on the join and the same collation. I am not sure why this would fail.

View 1 Replies

Connecting Two Mysql Tables From Different Databases?

How would you connect two tables from 2 different databases using PHP scripts? Because, one database that contains customer table is dedicated to one project, and then here comes another project that also uses the customer table...the clients dont want to reenter all of values from the first database to the second database. Dumping would not be an option cause they want the two projects to run in different databases... and whenever the user made changes to the customer table from the first database, it should also affect the customer table from the second database...

I need opinions now... I'm just starting to use php and mysql..

View 9 Replies

Connecting To Two Mysql Databases Simultaneously

is it possible to have two open connections to two different mysql dbs at the same time? when i tried it, only the one on the bottom of the list was active. my config file looks like this:

$dbname = 'xxx'; # Database Name
$dbuser = 'xxx'; # Database Username
$dbpass = 'xxx'; # Database Password
$dbhost = 'xxx'; # Database Host
$conn2 = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect to $dbname: ".mysql_error());
mysql_select_db($dbname) or die ("Could not access the database: ".mysql_error());


so i want to be able to do mysql_query($query,$conn2) when i need to access xxx db, but it doesn't seem to work that way.

View 4 Replies

Sqlsrv_connect() Not Found?

I recently am working on an projekt that uses the "SQL Server Driver for PHP", i wanted to upgrade the existing driver to the new version (2.0), because I need some of the functions that have been implemented there.

Now i replaced the old .dll in the php/ext directory and restarted the webserver. But now i recieve the following error:

Fatal error: Call to undefined function sqlsrv_connect() in E:ProjekteExternhades_aplclassessqlsqlsrv.class.php on line 34

But if i run phpinfo();, sqlsrv shows up, in the same way as the previous version did.

View 1 Replies

Multiple Databases

I have this site where I've installed phpBB Forum, B2evo blogs, A GB and PhpLinks. All of them have their own databases. I also have a Form where members can register. The Form has Login and PassWord entry fields and the values are stored in the Member master table in a different databse. Is there someway I could also populate the Login/Password of all the applications on submission of the above form.

View 1 Replies

Multiple Databases?

I'm trying to make secret forum avatars that people have to unlock but if I have 20 entries per user it's going to clog up my database fast, so I was thinking I could use a 2nd database for avatar info.

Is it possible to use multiple databases on a site? if so how? The 2nd database would only be accessed on 2 or 3 pages, but 2 would need to be accessed at once.

View 7 Replies

Using Sqlsrv_connect On Platforms Other Than Windows?

I've inherited some code that uses the sqlsrv_connect method to instantiate a connection to a SQL Server database. My personal development machine is an OS X box that I'm running apache an PHP on. I have an instance of SQL Server running in a virtual machine. When I attempt to connect to the database, I get the following error. Fatal error: Call to undefined function sqlsrv_connect() in ...It appears that sqlsrv_connect is not part of standard PHP, and is part of a driver that ships with SQL Server 2005. (please correct me if I'm wrong here Is there a way to use this function on Non-Windows platforms? I realize I could install/build an Apache/PHP instance on my Windows machine, but if there's a way to get this function working on OS X (or other *nixes) I'd prefer it.

View 3 Replies

PhpMyAdmin Multiple Databases

My new webhost gives me 5 databases for my website, my old host only had 1. I read somewhere how to setup your config.ini.php file in phpMyAdmin for multiple databases. I tried it and got the drop down menu but also recieved errors. The article I read said to just make a copy of this,

$cfg['Servers'][$i]['host'] = ''
$cfg['Servers'][$i]['port'] = ''
$cfg['Servers'][$i]['socket'] = ''
$cfg['Servers'][$i]['connect_type'] = 'tcp'
$cfg['Servers'][$i]['extension'] = 'mysql'
$cfg['Servers'][$i]['compress'] = FALSE;
$cfg['Servers'][$i]['controluser'] = ''
$cfg['Servers'][$i]['controlpass'] = ''
$cfg['Servers'][$i]['auth_type'] = 'config'
$cfg['Servers'][$i]['user'] = 'user'
$cfg['Servers'][$i]['password'] = 'password'
$cfg['Servers'][$i]['only_db'] = 'name'
$cfg['Servers'][$i]['verbose'] = ''
$cfg['Servers'][$i]['pmadb'] = ''

View 1 Replies

Searching Multiple Databases

Having a bit of a hard time getting my head round how to search multiple databases.
I've looked into the UNION function, but from my understanding (and please correct me if im wrong) you can search multiple databases but only if you have a field in each database that has the same name. e.g. PHP Code:


I was just wondering, would it be possible to do something like this: PHP Code:

SELECT * FROM TABLE01 LIKE "%$SearchInput%"
SELECT * FROM TABLE02 LIKE "%$SearchInput%"

View 4 Replies

Form To Multiple Databases

I have this site where I've installed phpBB Forum, B2evo blogs, A GB and PhpLinks. All of them have their own databases. I also have a Form where members can register. The Form has Login and PassWord entry fields and the values are stored in the Member master table in a different databse. Is there someway I could also populate the Login/Password of all the applications on submission of the above form. Would the member then be able to be "Logged In" while he accesses the different areas across the site? Or would it need a session varaiable or something like that.

View 1 Replies

Writing SQL For Multiple Databases?

Different databases have differences in SQL support & implementation. Sometimes there is a difference in SQL syntax, sometimes support for some SQL commands is missing, sometimes the database has a feature that other databases do not have.

What are considered to be good practices in writing SQL queries that are good for different databases (MySQL, PostgreSQL, Oracle, MSSQL, SQLite) taking in account that the developer uses a framework (like CakePHP, Codeigniter, Zend etc.) that provides a database abstraction layer? What SQL syntax should the developer try to avoid?

View 5 Replies

Multiple Queries On Different Databases?

Multiple queries on different databases.However not seem to return any error message nor any result set.common database connection file.

//database username and pass


View 6 Replies

Trouble With Multiple Mysql Databases

I'm having trouble accessing multiple databases using a single user.

Basically, I have 2 databases, db1 and db2 and 2 users, user1 and user2.
Originally these were setup so that user1 would only access db1 and user2
would only access db2. However, now I want user1 to access both db1 & db2.

I've used cPanel to declare user1 as a user of db2. However, whenever I try
to access db2 from user1, I get permission problems.

I've tried various combinations of mysql_db_select(), mysql_query("USE
db2Name", $db1link) or just referencing the appropriate table as
'db2Name.tableName' in my SELECT querys but everytime I get a permission
denied response.

Any ideas?. It looks like a cPanel problem to me as it appears that user1 is
simply not being granted access to db2 despite telling cPanel to do so.

View 1 Replies

Multiple Databases Item Counter

I have 25 shops and each shop is having between 80 to 125 items (items are identical but some shops may not sell all items).

I have a Shop database : shop1, shop2, etc...
I have a Item database : item1, item2, etc...

Now, I need how many times each item was sold per shop. Any idea on how I should proceed. I though the fastest would be to use .dat file (open, update) and not using databases.

View 1 Replies

Use Multiple Databases And Wordpress Installations?

Hey how do I showcase my themes like WooThemes has done. I don't want to use multiple databases and Wordpress installations? any reliable solution which lets me use the same database for all themes.

View 3 Replies

Create A Class For Use With Multiple Databases?

I'm attempting to create a class for use with multiple databases (don't tell me there are already classes that do this, I have an assignment to create my own). I'm attempting to capitalize on this functionality:


function test($value)
print $value;


But am having some difficulty figuring out the syntax to use in a class with a class wide variable. Here is the code:


$testLayer = new Test('root', 'a', 'test', 'mysql');
$sql = 'SELECT * FROM tblmedia';


I'm attempting to execute a function listed in the associative array utilizing the $$var syntax, but I'm unclear on how this is to be done on a class wide variable. This does not work, $this->{$$this->dbType}['query']($sql)

View 1 Replies

Copyrights 2005-15, All rights reserved