Story/oracle

php 에서 pear 를 사용해 oracle 값을 받아올때 컬럼명을 대문자 대신 소문자로 받고싶을때..

Stdio 2009. 4. 21. 10:54
반응형


pear 비디를 사용해서 오라클의 값을 받아올때 컬럼며을 대문자로만 사용해야 한다.
경우에 따라서 불편할때도 있어서 소문자로 받도록 수정을 해보았다.
pear 디비중 오라클을 사용하도록 해주는 파일 DB/oci8.php 파일에서 380라인쯤에

    function fetchInto($result, &$arr, $fetchmode, $rownum = null)
    {

        if ($rownum !== null) {
            return $this->raiseError(DB_ERROR_NOT_CAPABLE);
        }
        if ($fetchmode & DB_FETCHMODE_ASSOC) {
            $moredata = @OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE &&
                $moredata)
            {
                $arr = array_change_key_case($arr, CASE_LOWER);
            }
        } else {
            $moredata = OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
        }
        if (!$moredata) {
            return null;
        }
        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
            $this->_rtrimArrayValues($arr);
        }
        if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
            $this->_convertNullArrayValuesToEmpty($arr);
        }
        return DB_OK;
    }

위와 같은 fetchInto 함수가 있다
이 함수를

    function fetchInto($result, &$arr, $fetchmode, $rownum = null)
    {

        if ($rownum !== null) {
            return $this->raiseError(DB_ERROR_NOT_CAPABLE);
        }
        if ($fetchmode & DB_FETCHMODE_ASSOC) {
            $moredata = @OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE &&
                $moredata)
            {
                $arr = array_change_key_case($arr, CASE_LOWER);
            }
        } else {
            $moredata = OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
        }
        if (!$moredata) {
            return null;
        }
        // 추가된부분
        $arr = array_change_key_case($arr, CASE_LOWER);

        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
            $this->_rtrimArrayValues($arr);
        }
        if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
            $this->_convertNullArrayValuesToEmpty($arr);
        }
        return DB_OK;
    }
이와 같이 수정해서 소문자로 값을 사용할수있도록 수정할수가 있다.

반응형