public function testSubSubSelect() { $name = 'IBM'; $name2 = 'company'; $q = new ezcQuerySelect(ezcDbInstance::get()); $q->expr->setValuesQuoting(false); // subselect $q2 = $q->subSelect(); // sub subselect $q3 = $q2->subSelect(); $q3->expr->setValuesQuoting(false); $q3->select('*')->from('query_test2')->where($q3->expr->in('company', 'IBM', 'eZ systems')); // bind values $q2->select('company')->from('query_test')->where($q2->expr->eq('company', $q2->bindParam($name)), ' id > 2 '); $q->select('*')->from('query_test')->where(' id >= 1 ', $q->expr->in('company', $q2->getQuery()))->orderBy('id'); $stmt = $q->prepare(); $stmt->execute(); $result = $stmt->fetchAll(); $this->assertEquals('IBM', $result[0]['company']); $this->assertEquals('Norway', $result[0]['section']); $this->assertEquals('IBM', $result[1]['company']); $this->assertEquals('Germany', $result[1]['section']); }
<?php require_once __DIR__ . '/tutorial_example_01.php'; $name = 'IBM'; $q = new ezcQuerySelect(ezcDbInstance::get()); // Creating subselect object $q2 = $q->subSelect(); // $q2 will build the subquery "SELECT company FROM query_test WHERE // company = :ezcValue1 AND id > 2". This query will be used inside the SQL for // $q. $q2->select('company')->from('query_test')->where($q2->expr->eq('company', $q2->bindParam($name)), 'id > 2'); // $q the resulting query. It produces the following SQL: // SELECT * FROM query_test // WHERE id >= 1 AND // company IN ( ( // SELECT company FROM query_test // WHERE company = :ezcValue1 AND id > 2 // ) ) $q->select('*')->from('query_test')->where(' id >= 1 ', $q->expr->in('company', $q2)); $stmt = $q->prepare(); echo $stmt->queryString; //$stmt->execute();