Hello people, I am now beginning to practice php, but I'm having a little problem ... PHP File DRIVERS are asking SQL to perform the test ... but we have done everything possible in order to install the drivers on my server (AppServ)
Can anyone shed some light?
Script:
<?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.');
}
// Checks whether we need to do some housekeeping
// and installs table values if required.
function checkNeedsTableValueInstall($conn) {
if($conn) {
$sql_query = "IF NOT EXISTS(SELECT [TYPE] FROM [TA_SECURITY_TYPE_ACC] WHERE TYPE = 1)
INSERT INTO [TA_SECURITY_TYPE_ACC]
( [TYPE], [TYPE_NM], [USE_YN] )
VALUES
( 1, N'UCC', 'Y' )";
sqlsrv_query($conn, $sql_query);
} else {
die("ERR_SRVVAR");
}
}
// Checks whether the UCC folders need creating and does so if necessary
function createUccDirectoryAndGetTargetDir($fileName, $ucctype) {
global $__ucc_path;
$fname_parts = explode("_", $fileName);
$last_part = $fname_parts[count($fname_parts) - 1];
$last_part_clean = str_replace(".jpg", "", $last_part);
$first_letter_dir = ucfirst(substr($last_part_clean, 0, 1));
$ucc_file_path = $__ucc_path . $ucctype . '/' . $first_letter_dir . '/';
if(!file_exists($ucc_file_path))
mkdir($ucc_file_path, 0, true);
return $ucc_file_path;
}
// Opens a new database connection and returns the handle
function getDbConnection() {
global $__sql_srv, $__sql_db, $__sql_user, $__sql_pass;
$connectionInfo = array('UID' => $__sql_user, 'PWD' => $__sql_pass, 'Database' => $__sql_db);
$conn = sqlsrv_connect( $__sql_srv, $connectionInfo);
return $conn;
}
// Closes a database connection
function closeDbConnection($conn) {
sqlsrv_close($conn);
}
// Update the Security Key in the database to ensure
// it cannot be used again (i.e. for replay attacks)
function deleteSecurityKey($key, $conn) {
if($conn) {
$sQuery = "UPDATE [TD_SECURITY_KEY] SET [USE_YN] = 'N' WHERE [SKEY] = (?)";
$sParams = array(&$key);
$stmt = sqlsrv_prepare($conn, $sQuery, $sParams);
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
} else {
die("ERR_SRVVAR");
}
}
// Verify the given Security Key against the database.
// If key is valid, TRUE will be returned and the key will be deleted.
function checkSecurityKeyIsValid($key, $item_id, $type, $conn) {
if($conn) {
$sQuery = "SELECT COUNT(SKEY) FROM [TD_SECURITY_KEY] WHERE [ITEM_ID] = (?) AND [SKEY] = (?) AND [TYPE] = (?) AND [USE_YN] = (?)";
$sParams = array(&$item_id, &$key, &$type, 'Y');
$stmt = sqlsrv_prepare($conn, $sQuery, $sParams);
$retVal = sqlsrv_execute($stmt);
sqlsrv_fetch($stmt);
$isValid = sqlsrv_get_field($stmt, 0);
sqlsrv_free_stmt($stmt);
if($isValid === 1) {
deleteSecurityKey($key, $conn);
return true;
} else
return false;
} else {
die("ERR_SRVVAR");
}
}
?>