Creating a function to grab data from an Oracle database (array by ID)

后端 未结 1 761
挽巷
挽巷 2021-01-25 03:04

I\'m trying to create a function that will simply allow me to pass an SQL statement into it, and it will generate an array based on a unique ID I pass it:

functi         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 03:51

    Untested and without proper error handling:

    function oracleGetGata($query, $id="id") {
        global $conn;
    
        $results = array();
        $sql = OCI_Parse($conn, $query);
        OCI_Execute($sql);
        while ( false!==($row=oci_fetch_assoc($sql)) ) {
            $results[ $row[$id] ] = $row;
        }
        return $results;
    }
    

    0 讨论(0)
提交回复
热议问题