这是我的php文件 - 我的问题是页面在执行存储过程之前显示标题。我所追求的是让存储过程执行,然后执行select语句,然后在屏幕上显示结果。我是否需要使用与Thread.Sleep()
类似的内容,以确保存储的proc有时间在代码继续之前完全执行?
如果您需要查看我的调用过程语法,请告诉我,我也可以添加它。但是为什么在存储过程执行并执行select语句之前,语法显示表头?我以为php会按顺序做事吗?
//PDO Connection
$hostname = 'Ragweed';
$dbname = 'Test';
$username = 'testuser';
$password = 'ghost';
$dbh = new PDO("dblib:host=$hostname;dbname=$dbname","$username","$password");
$ramalad = implode(',',$_REQUEST['ramalad']);
$df = $_REQUEST['df'];
$dt = $_REQUEST['dt'];
//Run SQL Server Parameter Stored Procedure
$sql = 'CALL storedproc(?,?)';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(1, $df, PDO::PARAM_STR);
$stmt->bindParam(2, $dt, PDO::PARAM_STR);
$stmt->execute();
//Select the selected fields from the newly created table
$sql = "SELECT ".$ramalad." FROM tablefromstoredproc";
$stmt = $dbh->prepare($sql);
$stmt->execute();
//Generate Header for Table
$counter = 0;
$width = count($_REQUEST['ramalad'])*110;
echo '<div style="width:'.$width.'px;border:1px solid #ccc;margin-top: 30px;">';
echo '<div style="width:'.$width.'px;background-color:#ccc;height:30px;">' ;
if(in_array('EmpName',$_REQUEST['ramalad'])){ echo '<div style="width:105px; float:left; margin-right:5px;text-align: center;">Employee</div>'; }
if(in_array('EmpID',$_REQUEST['ramalad'])){ echo '<div style="width:105px;float:left;margin-right:5px;text-align: center;">EmployeeID</div>'; }
if(in_array('EmpHireDate',$_REQUEST['ramalad'])){ echo '<div style="width:105px;float:left;margin-right:5px;text-align: center;">Hire Date</div>'; }
echo "</div>";
while ($row = $stmt->fetch()) {
if($counter%2 == 0 ){ echo '<div style="width:'.$width.'px;height:50px;">'; }
else { echo '<div style="width:'.$width.'px;background-color:#ccc;height:50px;">'; }
if(isset($row["EmpName"])){ echo '<div style="width:105px; float:left; margin-right:5px;text-align: center;">'.$row["EmpName"].'</div>'; }
if(isset($row["EmpID"])){ echo '<div style="width:105px;float:left;margin-right:5px;text-align: center;">'.$row["EmpID"].'</div>'; }
if(isset($row["EmpHireDate"])){ echo '<div style="width:105px;float:left;margin-right:5px;text-align: center;">'.$row["EmpHireDate"].'</div>'; }
echo "</div>";
$counter++;
}
unset($dbh); unset($stmt);
修改
从评论和我的谷歌搜索php语法是同步的,所以它应该执行第1行,然后第2行,然后第3行等。这就是为什么我的存储过程和选择语句没有被执行?