0

Im executing this query:

$query = "
    Select * From table1 Where id = 1;
    Select * From table2 Where name = 'test';
";

With \Zend\Db\Adapter\Adapter:

$stmt = $this->dbAdapter->query($query);
$rawResult = $stmt->execute();

How can I access the second result? $rawResult->next() only returns values from first query.

Dennis
  • 7,907
  • 11
  • 65
  • 115
stefen
  • 39
  • 6

1 Answers1

0

Use two different queries.

/*
 * First Query
 */
$query = "
    Select * From table1 Where id = 1
";
$stmt = $this->dbAdapter->query($query);
$rawResult = $stmt->execute();

/*
 * Second Query
 */
$query = "
    Select * From table2 Where name = 'test'
";
$stmt = $this->dbAdapter->query($query);
$rawResult = $stmt->execute();

I don't believe it works the way you had it to where two queries in a row are sent this way.

To avoid code duplication you can wrap the duplicated code into a method.

$rawResult1 = $this->getResults("Select * From table1 Where id = 1");
$rawResult2 = $this->getResults("Select * From table2 Where name = 'test'");

function getResults(string $query)
{
    $stmt = $this->dbAdapter->query($query);
    return $stmt->execute();
}
Dennis
  • 7,907
  • 11
  • 65
  • 115
  • Ok thanks. May you can help me here (: http://stackoverflow.com/questions/42859322/zend-2-sqlsrv-prepareparams-not-setted/42884181#42884181 – stefen Mar 23 '17 at 21:42