I am using zend framework3 and using the Mysql driver for the database. I am using the below code to get the data:
$con = $this->adapter;
$select = $this->sql->select();
$select->from('nav_menu');
$selectString = $this->sql->getSqlStringForSqlObject($select);
$results = $con->query($selectString, $con::QUERY_MODE_EXECUTE);
$resultSet = new ResultSet();
$resultSet->initialize($results);
when i var_dump this data i am getting the result as below:
Zend\Db\ResultSet\ResultSet Object
(
[allowedReturnTypes:protected] => Array
(
[0] => arrayobject
[1] => array
)
[arrayObjectPrototype:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
[returnType:protected] => arrayobject
[buffer:protected] =>
[count:protected] =>
[dataSource:protected] => Zend\Db\ResultSet\ResultSet Object
(
[allowedReturnTypes:protected] => Array
(
[0] => arrayobject
[1] => array
)
[arrayObjectPrototype:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
[returnType:protected] => arrayobject
[buffer:protected] => -1
[count:protected] =>
[dataSource:protected] => Zend\Db\Adapter\Driver\Mysqli\Result Object
(
[resource:protected] => mysqli_result Object
(
[current_field] => 0
[field_count] => 8
[lengths] =>
[num_rows] => 15
[type] => 0
)
[isBuffered:protected] => 1
[position:protected] => 0
[numberOfRows:protected] => -1
[currentComplete:protected] =>
[nextComplete:protected] =>
[currentData:protected] =>
[statementBindValues:protected] => Array
(
[keys] =>
[values] => Array
(
)
)
[generatedValue:protected] => 0
)
[fieldCount:protected] => 8
[position:protected] => 0
)
[fieldCount:protected] =>
[position:protected] => 0
)
I am getting an error When i am iterating this to get the value as below:
foreach ($resultSet as $key => $value) {
$array[$i]['id'] = $value->id;
$array[$i]['name'] = $value->name;
$array[$i]['label'] = $value->label;
$array[$i]['route'] = $value->route;
$array[$i]['parent_id'] = $value->parent_id;
$i++;
}
I don't where i am wrong. While there are num_rows is 15. This is working in ZF2 fine. Any help from any one is appreciated.
I tried a lot and find that if replace the code
$selectString = $this->sql->getSqlStringForSqlObject($select);
$results = $con->query($selectString, $con::QUERY_MODE_EXECUTE);
with the
$statement = $this->sql->prepareStatementForSqlObject($select);
$results = $statement->execute();
then i get the result.But my question why i am not getting the result through
$selectString = $this->sql->getSqlStringForSqlObject($select);
$results = $con->query($selectString, $con::QUERY_MODE_EXECUTE);