Returning a Recordset from a Funtion
| From: | David Stoltz | Date: | Fri, 25 Jun 2010 13:55:59 +0000 |
| Subject: | Returning a Recordset from a Funtion | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-306425@lists.php.net to get a copy of this message | ||
Hi Folks,
Upon occasion, I have the need to hit our MS MSL database from our
PHP/mySQL server. So I've created a function, but I'm not sure if you
can return a recordset from a function. My code is below...
In the calling page I code:
<?php
include('../includes/mssql.php');
hitMSSQL("server","database","username","password","SELECT
* FROM
TABLE1");
echo $rs->Fields(1);
?>
The mssql.php include file is:
<?php
function hitMSSQL($server,$db,$login,$pass,$query){
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");
$connStr =
"PROVIDER=SQLOLEDB;SERVER=".$server.",1433;UID=".$login.";PWD=".$pass.";
DATABASE=".$db;
$conn->open($connStr);
$rs = $conn->execute($query);
return $rs;
}
?>
If I have the echo statement in the function, it works.
And of course I can return a single value like:
Return $rs-Fields("value");
But I can't return the whole recordset...
Does anyone have any good ideas so I can access the recordset in the
calling page?
Thanks!