I am developing a small web application on my XAMPP (5.6.8) localhost that is selecting data from two remote databases, one is MySQL and one is MSSQL.
I'm unsure how to connect to both of these databases within a single conn.php file - if it's even possible?
I am able to use HeadiSQL & SQL Server Management Studio to login to each database, run queries and retrieve data, so I know it's not a user permissions issue. Note: I am not the admin of either of these databases.
I have one conn.php file that I include throughout my web application. The contents of this file are below.
When I include the MSSQL connection lines I receive the following error message on my web app;
localhost is currently unable to handle this request. HTTP ERROR 500
When I delete the MSSQL connection lines my web app loads as normal. Should I be connecting to the MSSQL database in a different way, this is clearly the issue.
conn.php
<?php
// Create MySQL connection
$conn = new mysqli('123.123.123.123', 'db_user', 'password', 'db_name');
if ($conn->connect_errno > 0) {
die('Unable to connect to database [' . $conn->connect_error . ']');
}
// end MySQL connection
//Create MSSQL connection
$serverName = "456.456.456.456";
$connectionInfo = array( "Database"=>"db_name", "UID"=>"db_user", "PWD"=>"password");
$conn2 = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn2 ) {
echo "Connection established to smartcard.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
// end MSSQL connection
?>
I've also created a separate conn_1.php page which contains only the MSSQL connection code. When I visit this page in my browser I see the following error;
localhost is currently unable to handle this request. HTTP ERROR 500
Any help is appreciated.