I cannot connect to the database within a PHP function, but have no difficulty outside the function. Googling around has not found solution. I am using PHP SQLSRV not MSSQL for the connection. This connection works elsewhere. This is the simple PHP:-
<?php
include("dbconfig.php");
//last line of this: $conn = sqlsrv_connect($serverName, $connectionInfo)
function listCalendar(){
$sql = "select Id from Calendar";
$handle = sqlsrv_query($conn,$sql);
while ($row = sqlsrv_fetch_object($handle)) {
$ret= "result = ".$row->Id;
}
return $ret;
}
listCalendar(); ?>
This does not even generate an empty "result = ". If the line function listCalendar(){ and closing tag } are commented out, and return $ret replaced by echo $ret, then the correct "result = 5" is echoed. Grateful for ideas as have wasted much time on this!