I want to use two databases with one silver in the script, but the query does not work. My connections:
$serverName = "12.354.25.5"; //serverName\instanceName
//first
$connectionInfo = array( "Database"=>"GRQ", "UID"=>"RFUser", "PWD"=>"****", "CharacterSet" => "UTF-8");
global $con;
$con = sqlsrv_connect( $serverName, $connectionInfo);
//second
$connectionpyr = array( "Database"=>"PiF", "UID"=>"greystone", "PWD"=>"****", "CharacterSet" => "UTF-8");
global $conpyr;
$conpyr = sqlsrv_connect( $serverName, $connectionpyr);
First connection is work fine, i use select by this and get data:
$SQL = "SELECT id,col1,col8,col9 FROM [dbo].[RF_TableWHERE ID=".$data[$k]."";
$result = sqlsrv_query($con,$SQL); //it work fine
Using the second connection, I try to execute a stored procedure,
$VER = "DECLARE @Debt MONEY, @ResultMsg NVARCHAR(255)
EXEC Pyramid.dbo.CheckDebt @AccountNumber =".$numlic.", -- int
@PeriodFrom = '".$dstart."', -- date
@PeriodTo = '".$dend."', -- date
@Debt = @Debt OUTPUT, -- money
@ResultMsg = @ResultMsg OUTPUT -- nvarchar(500)
";
$result2 = sqlsrv_query($conpyr,$VER);
but get only
An invalid parameter was passed to sqlsrv_query.
Resource ID of connection two is empty (nothing)
How resolve this?
If you have more than 1 database connections, you should close the connection1 before you start the connection to db2.