I'm trying to upgrade from PHP v5.4 to php v7.0, where I ran into this issue of being unable to run the inner nested query. I'm was using pdo_sqlsrv for my SQL server but since the PDO drivers for it aren't yet available for PHP v7.0, I switched to pdo_odbc. Is being able to run nested queries specific to sqlsrv? I've added some test code to make my situation clear. DBTEST class for the PDO instance:
class DBTEST{
private static $instance = null;
public static function getInstance(){
$userid = "testUser";
$pwd = "love-da-poe-poes";
self::$instance = new PDO("odbc:testdb", $userid, $pwd);
return self::$instance;
}
}
Nested Queries:
$parentQuery = "Select pid from Tree";
$parentResult = DBTEST::getInstance()->prepare($parentQuery);
$parentResult->execute();
$childQuery = "Select cid, cname from Tree where pid = ?";
$childResult = DBTEST::getInstance()->prepare($childQuery);
while($parentObject = $parentResult->fetchObject()){
$childResult->bindParam(1, parentResult->pid, PARAM_INT);
$childResult->execute();
while($childObject = $childResult->fetchObject()){
//do something with results
}
}