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?