dongle3217 2015-09-23 09:07
浏览 73

Oracle + PHP - OCI结果数据类型

I would like to ask if it is possible to fetch the result of select query to array of objects which will have the properties of same types (only supported) as the columns in select statement.

This code in my php service

            $stid = oci_parse($this->conn, "SELECT TO_DATE('2015-09-23','YYYY-MM-DD') AS DATE_COLUMN, 'some text' AS TEXT_COLUMN, 6 AS INTEGER_COLUMN, 3.14 AS DOUBLE_COLUMN FROM DUAL");

            oci_execute($stid);

            $ncols = oci_num_fields($stid);

            for ($i = 1; $i <= $ncols; $i++) {
                $column_name = oci_field_name($stid, $i);
                $column_type = oci_field_type($stid, $i);
                $column_size = oci_field_size($stid, $i);
                echo "name: ".$column_name.", type: ".$column_type.", size: ".$column_size."
";
            }
            echo "
";

            //oci_fetch_all($stid, $res, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
            $res = array();
            while (($row = oci_fetch_object($stid)) != false) {
                var_dump(get_object_vars($row));
                array_push($res, $row);
            }

            oci_free_statement($stid);

will return this output:

            name: DATE_COLUMN, type: DATE, size: 7
            name: TEXT_COLUMN, type: CHAR, size: 9
            name: INTEGER_COLUMN, type: NUMBER, size: 2
            name: DOUBLE_COLUMN, type: NUMBER, size: 3

            array(4) {
              ["DATE_COLUMN"]=>
              string(8) "23.09.15"
              ["TEXT_COLUMN"]=>
              string(9) "some text"
              ["INTEGER_COLUMN"]=>
              string(1) "6"
              ["DOUBLE_COLUMN"]=>
              string(4) "3,14"
            }

Why the datatypes of object properties are not the same as the datatypes of columns? Is there any other function in oci8 to do this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助
    • ¥15 STM32控制MAX7219问题求解答