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 t开发者_如何学编程o this topic. if i made any mistake pls do correct.
try this:
$result = $DB->fetchOne("SELECT name FROM table_name WHERE id=1");
This code will execute your query through doctrine
getServiceLocator()
. With the help ofcreateQueryBuilder()
, 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.
精彩评论