Doctrine2 INDEX By Array Format -


i trying fetch data using doctrine 2, array result has id in index of array , other column value index.

the format trying :      [country_id] = country 

i not sure if possible.

$dql = "select c.country user\entity\country c index c.country_id";         $dq = $em->createquery($dql);         $countries = $dq->getresult(query::hydrate_array);                 $em->clear(); 

current result:

[0] => array ( [country] => afghanistan )

[1] => array ( [country] => aland islands )

[2] => array ( [country] => albania )

required result:

[0] => afghanistan

[1] => aland islands

[2] => albania

i not sure how way, know how used :

$conn = $this->getentitymanager()->getconnection(); $sql = "select c.country country c;"; $query = $conn->prepare($sql); $query->execute(); $result = $query->fetchall(\pdo::fetch_column); 

the result should single array without having array inside array fetch_column return value of column , not array index.

edit :

to keep index have create custom hydrator :

protected function _hydrateall()     {         return $this->_stmt->fetchall(pdo::fetch_column);     } 

this way keep index , using fetch_column @ same time.

i put code function because link below give need part changed fetch_column should correct.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#custom-hydration-modes


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -