0

我正在尝试访问存储过程,让它执行并使用 html 表来显示结果。我现在使用带有 mssql_init 和 mssql_execute 的 PHP.net 的代码:

?php
$month = $_POST['month'];
$year = $_POST['year'];
$dayfrm = $_POST['creditfrm'];
$dayto = $_POST['creditto'];
$crdayfrm = date("F j, Y", strtotime($dayfrm));
$crdayto = date("F j, Y", strtotime($dayto));
$monthhd = date("F Y", strtotime("$year-$month"));
$monthfrm = date("Y-m-d", strtotime("$year-$month"));
$monthto = date("Y-m-d", strtotime("$year-$month . +1 month"));
echo $monthfrm;
echo $monthto;
$date = date("F j,Y");
$stopro = "usp_CreditMemo";

if ($_POST['credsubmit']) {
        include('includes/header.php');
        echo "<title>Credit Memo Report for $monthhd</title>";
        print('<link rel="Shortcut Icon" href="liferay.ico" />');
        print('<head>');
        print('<link href="helper.css" media="screen" rel="stylesheet" type="text/css" />');
        print('<link href="dropdown.css" media="screen" rel="stylesheet" type="text/css" />');
        print('<link href="default.css" media="screen" rel="stylesheet" type="text/css" />');
//      include('includes/connection.php');
// Performing SQL query
$db = mssql_connect("10.xx.xx.xx","UN","PW");
mssql_select_db("DBName",$db);
$stmt = mssql_init('usp_StoredName');
mssql_bind($stmt, '@dateFrom',  '2012-05-01',   'SQLINT4',      false,  false,  20);
mssql_bind($stmt, '@dateTo',    '2012-06-01',   'SQLINT4',      false,  false,  20);
$result = mssql_execute($stmt)  or die('Query failed: ' . mssql_get_last_message());
// Printing results in HTML
echo "<h2 align=center style=margin-top:20>Credit Memo Report for: $monthhd</h2>";
echo "<table class=rptstable width=80%>\n";
print('<tr class="trstyle"><td>ID</td><td>DDI</td><td>Date</td><td>Amount</td><td>Name</td><td>Comments</td><td>Internal</td><td>Racker</td><td>Consolidated Inv.</td></tr>');
while ($line = mssql_fetch_array($result, MSSQL_ASSOC)) {
  echo "\t<tr>\n";
  foreach ($line as $col_value) {
      echo "\t\t<td>$col_value</td>\n";
  }
  echo "\t</tr>\n";
}
echo "</table>\n";// Free resultset
mssql_free_result($result);// Closing connection
mssql_close($db);
}

当我这样做时,我得到一个空白页。如果我取出 mssql_bind,它会收到一条错误消息,指出存储过程需要 @date 输入。但是,他将其绑定为白页,没有错误消息显示,这一直意味着语法错误。我希望能够从名为 $monthfrm 和 $monthto 的表单中传递变量,但一次执行步骤。

每隔一段时间,根据我放入或取出的内容,我会收到一条错误消息,提示查询失败:将数据库上下文更改为“DBname”。

4

0 回答 0