I have following function which returns multiple rows of data, but it is returning separate arrays:
function getAllDataByID($uid)
{
try {
$conn = DB::db_connect();
$sql = "Select id from tbl1 where uid =:uid";
$query = $conn->prepare($sql);
$query->execute(array(':uid'=>$uid));
$query->setFetchMode(PDO::FETCH_ASSOC);
return $query;
}
catch (Exception $e) {
return $e->getMessage();
}
}
output:
array(1) {
["id"]=>
string(2) "22"
}
array(1) {
["id"]=>
string(2) "21"
}
array(1) {
["id"]=>
string(2) "18"
}
Whereas I want it to be a nested array.