1

I want to use some thing likes this:

SELECT * FROM table WHERE NOT(other where);

Other wheres are like

A = 1 AND B = 3

Values of A and B are not static. How can I use zend-db to get this query?

$where->addPredicate(new PredicateExpression('NOT (?)', (new Where())->equalTo(A = $value));
Daron
  • 11
  • 1

2 Answers2

0

This always works for me.

$select->columns(['first_name', 'last_name']); $select->from(['U', 'USER']); $select->where->equalTo('first_name', 'Larry'); $select->where->expression("NOT(last_name) = 'Harry'", []);

Daedalus
  • 255
  • 1
  • 2
  • 9
0

I really don't get your question completely, but what i got is you want to put a variable in 'where' inside a query for zend-framework2.

Take this for example, This query returns all student ids and names WHERE the $id is matched from table Students

 $qb = $entityManager->createQueryBuilder();
                $qb->select(array(
                    'PersonalInfo.studentId as studentId',
                    'PersonalInfo.name as studentName',
           ))
                    ->from('Application\Entity\Students', 'PersonalInfo')
                    ->where('PersonalInfo.studentId = :Info')
                    ->setParameter('Info', $id);
                $student = $qb->getQuery()->getScalarResult();

As you can see, in the where portion we have put :info, which is called alias, we give a value to this alias, in the setParameter, where you can see a variable $id. So $id is a random variable which value can be changed. I hope this helps, If you need further instructions, let me know.

Seeker
  • 303
  • 7
  • 17