1

Thanks for previous replies

I am execution "select Name from table_name where id=1"; . i saw some tutorials for getting data from the database, they mentioned $DB = new Zend_Db_Adapter_Pdo_Mysql($params); DB->setFetchMode(Zend_Db::FETCH_OBJ); and the result will getting through $result = $DB->fetchAssoc($sql); This $result is an array format, i want to get only name instead of getting all the data from the database. I am new to this topic. if i made any mistake pls do correct.

2 Answers 2

3

try this:

$result = $DB->fetchOne("SELECT name FROM table_name WHERE id=1");
Sign up to request clarification or add additional context in comments.

Comments

0

This code will execute your query through doctrine getServiceLocator(). With the help of createQueryBuilder(), you can write your query directly into zend-framework2, and with setParameter, any desired condition would be set easily.

$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                $qb = $entityManager->createQueryBuilder();
                $qb->select(array(
                    'TableName.columnName as columnName '


                ))
                    ->from('ProjectName\Entity\TableName', 'TableName')
                    ->where('TableName.TableId = :Info')
                    ->setParameter('Info', $id);
                $var= $qb->getQuery()->getScalarResult();

The $var variable holds the value for which, you wanted the comparison to be made with, and holds only the single values of your interest.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.