Oracle + PHP - OCI结果数据类型

时间:2015-09-23 09:07:44

标签: php oracle sqldatatypes oci

我想问一下是否可以将select查询的结果提取到对象数组中,这些对象将具有与select语句中的列相同类型(仅支持)的属性。

我的php服务中的代码

            $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."\n";
            }
            echo "\n";

            //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);

将返回此输出:

            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"
            }

为什么对象属性的数据类型与列的数据类型不同?在oci8中还有其他功能吗?

0 个答案:

没有答案