I have some db table like this. This table contains strings
and numbers
, but some fields (type: text) contains []
arrays and {}
objects(json) (empty or not).
+------+----------+------+--------+--------+---------+-----------+
| name | lastName | type | delete | rights | records | documents |
+------+----------+------+--------+--------+---------+-----------+
| varch| varchar | int | int | text | text | text |
+------+----------+------+--------+--------+---------+-----------+
| An | Blabla | 0 | 0 | [] | {"a": 1}| {12: {}}|
+------+----------+------+--------+--------+---------+-----------+
| Bn | Blablab | 5 | 0 | [2,3] | {} | {} |
+------+----------+------+--------+--------+---------+-----------+
DB request:
$stmt = $this->db->prepare('select ' . USER_TABLE_FIELDS .' from users where
name = :name');
$stmt->execute(array(':name' => $name));
$result1 = $stmt->fetch(PDO::FETCH_ASSOC);
and in var $result1 I have array this $key (string
) and $value(string
for all fields).
How can I fetch result for fileds rights
as array, records
as object, documents
as object, not string?
And I know about (object) $var
and (array) $var
, but probably there is more simple way, becouse it can be multilevel in future.