Hvorfor returnerer PHP kun EN row?
Jeg har problemer med at få returneret mere end en row.Kode:
<?php
include 'DBconnZeus.php';
$sql = "SELECT * FROM DB_Menu where active = 1 and parentID is null";
$getmenu = DB_Conn_Zeus ('Redaktion',$sql);
var_dump($getmenu);
?>
Og DBconnZeus indeholder:
<?php
function DB_Conn_Zeus ($dbname, $tsql)
{
$serverName = "10.0.0.0";
$uid = "sa";
$pwd = "123456";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$dbname);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
//echo "Connection established.<br />";
}
else
{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in query preparation/execution.<br />";
die( print_r( sqlsrv_errors(), true));
}
/* Retrieve each row as a PHP object and display the results.*/
while( $obj = sqlsrv_fetch_object( $stmt))
{
Echo "Found: ".$obj->ID."<br>";
return $obj;
}
/* Close the connection. */
sqlsrv_close( $conn);
}
?>
Ligemeget hvad, kommer den kun ud med den første række den finder. Så der må være et eller andet galt i min while lykke? Men hvad?