New Here - With First Question About Multiple Query Calls

Hi, First off I’m grateful for you. I hope to answer when I can, but I expect I will ask more than I answer. I have worked for several years with PHP and SQL, but I took a few years off and now I’m trying to get back in using PDO connections (new to me). I want to be able to in a single script, run query1, get an answer, and make it the variable of query 2. Run query 2 and show results. Here’s my code…

<?php include 'ConnectHACAPHP.php'; include 'ViewCols0331.php'; $stmt = $conn->prepare("Select month(lastclose) from XXXPHP..LastCloseDate "); $stmt->execute(); $monthnumarr = $stmt->fetch(); $monthnum = $monthnumarr[0]; $stmt->closecursor(); $periodcol = $viewcols0331[$monthnum][0]; echo "Select ".$periodcol. " from [EliteLivePHP].[dbo].[XXX2020] "; $stmt2 = $conn->prepare("Select ".$periodcol. " from [XXXPHP].[dbo].[XXX2020] "); echo "
here1"; $stmt2->execute(); echo "
here2"; $resultarr = $stmt2->fetch( FETCH_NUMERIC ); echo $resultarr[0]; ?>

The output is : Select Period11 from [XXXPHP].[dbo].[XXXFY2020]
here1

so the 1st query seems to get the variable for the 2nd query and II can see it can write the query ok, but it seems to stop at $stmt2->execute();

Any advice?