Connecting to multiple servers in SSP
Connecting to multiple servers in SSP
Hi Allan, is there a way to connect to multiple severs using $sql_details
?
For example, for use in my other scripts, I have included something like this to switch between different servers when presented with tm-charts.dev vs. tm-charts.splashworldwide.com:
<?php
// configure your database connection here
$dbConfig = array();
$dbConfig['tm-charts.splashworldwide.com'] = array(
'user' => 'chartsusr',
'pass' => 'mkNvZ77TtwsNsq',
'name' => 'tmcharts',
'host' => 'localhost',
);
$dbConfig['tm-charts.dev'] = array(
'user' => 'root',
'pass' => 'root',
'name' => 'tm-charts',
'host' => 'localhost',
);
$hostName = $_SERVER['HTTP_HOST'];
if (!array_key_exists($hostName, $dbConfig)) {
die ('Unknown host');
}
$currentConfig = $dbConfig[$hostName];
I need to update the server-side processing script that is being used for my DataTables to do something similar. What I currently have is:
// sql server connection information
$sql_details = array(
'user' => 'root',
'pass' => 'root',
'db' => 'tm-charts',
'host' => 'localhost'
);
I need that to be edited to use different login details when viewing the site from tm-charts.splashworldwide.com. Please let me know if you have any questions about this. Thank you for your help!
This question has an accepted answers - jump to answer
Answers
Hi,
There isn't any option to connect to multiple servers at the same time using the single connection that the Editor database libraries use, but it should be perfectly possible to use exactly the same approach as you have for your own
$dbConfig
.The
config.php
file is just a regular PHP file, so you can put any code you want in there (including your$_SERVER['HTTP_HOST']
check) and just assign the required array to the$sql_details
global variable.It is also possible to supply your own PDO connection resource for the Editor libraries:
That can be useful if you already have a PDO connection you want to use.
Regards,
Allan