Function for querying Oracle database - 'Undefined index' notice
===

To give some context, a little while ago with the help from VolkerK on this very site I created a function that queries an Oracle database and places the content into a neatly formatted PHP array, depending on the index. [Here's the original question][1].

The problem is, in some cases I just want to return a single value from a quick query, and when I do I get the the following error: `Notice: Undefined index: `

Here's the code I'm using:

    function oracleGetData($query, $id = null) {
    	global $conn;
    	
    	$results = array();
    	$sql = OCI_Parse($conn, $query);
    	OCI_Execute($sql);
    	while ( false!==($row=oci_fetch_assoc($sql)) ) {
    		$results[ $row[$id] ] = $row;
    	}
    	
    	// remove one layer if there's only one record
    	if(count($results) == 1 and is_null($id)) {
    		$results = array_pop($results);
    	}
    	return $results;
    }

I have tried changing the line that populates the array like so:

	if(is_null($id)) {
		while ( false!==($row=oci_fetch_assoc($sql)) ) {
			$results[ $row ] = $row;
		}
	} else {
		while ( false!==($row=oci_fetch_assoc($sql)) ) {
			$results[ $row[$id] ] = $row;
		}
	}

Basically if the $id variable is null, remove all references to it, but then I get a 'Warning: Illegal offset type' error.

Any help would be much appreciated, I've tried passing in the single field I require into the function but get the same error.

Thank you


  [1]: http://stackoverflow.com/questions/9803202/creating-a-function-to-grab-data-from-an-oracle-database-array-by-id