我正在尝试访问存储过程,让它执行并使用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”。