Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in C:\AppServ\www\wpy\InGame\NoticeRSS_functions.php on line 21
Code (PHP)
<?php
// Checks whether the sqlsrv driver is installed and dies if not.
function checkSqlsrvDriverInstalledOrDie() {
if(!function_exists('sqlsrv_connect'))
die('This software requires <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80E44913-24B4-4113-8807-CAAE6CF2CA05">Microsoft\'s SQL Server Driver for PHP</a>.<br />
The old mssql and odbc drivers are not fully compatible with SQL Server 2008.');
}
// Opens a new database connection and returns the handle
function getDbConnection($toDatabase) {
global $__sql_srv, $__sql_user, $__sql_pass;
$connectionInfo = array('UID' => $__sql_user, 'PWD' => $__sql_pass, 'Database' => $toDatabase);
$conn = sqlsrv_connect($__sql_srv, $connectionInfo);
return $conn;
}
// Closes a database connection
function closeDbConnection($conn) {
sqlsrv_close($conn);
}
// Generates a "ver" value for the output notice to determine
// whether it needs to be updated or not.
function getLatestVerForGuild($guild, $conn) {
if($conn) {
$sQuery = "SELECT TOP 1 [EditDate] FROM Pangya_Guild_Notice WHERE [Guild_Id] = (?) AND [Valid] = (?) AND [Published] = (?) ORDER BY [EditDate] DESC";
$sParams = array(&$guild, 1, 1);
$stmt = sqlsrv_prepare($conn, $sQuery, $sParams);
$retVal = sqlsrv_execute($stmt);
if(sqlsrv_has_rows($stmt) && $retVal == 1) {
sqlsrv_fetch($stmt);
$latestDt = sqlsrv_get_field($stmt, 0);
sqlsrv_free_stmt($stmt);
return $latestDt->getTimestamp();
} else {
die();
}
}
die('No connection to database.');
}
function getNoticesForGuild($guild, $conn) {
if($conn) {
$sQuery = "SELECT TOP 10 * FROM Pangya_Guild_Notice WHERE [Guild_Id] = (?) AND [Valid] = (?) AND [Published] = (?) ORDER BY [EditDate] DESC";
$sParams = array(&$guild, 1, 1);
$stmt = sqlsrv_prepare($conn, $sQuery, $sParams);
$retVal = sqlsrv_execute($stmt);
if(sqlsrv_has_rows($stmt)) {
$results = array();
while($notice = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$results[] = $notice;
}
sqlsrv_free_stmt($stmt);
return $results;
} else {
die();
}
}
}
?>