-1
我在Windows 2012服務器上使用SQL 2012中的數據庫。我在我的代碼中使用連接字符串連接到它時遇到了一些問題。我已經通過網絡對它進行了測試,並且使用Visual Basic和Excel無任何問題地連接到它。我很難過,因爲我無法連接到它,它與我的代碼有關,我確信它。額外的一雙眼睛會有所幫助。2012 SQL連接字符串500內部服務器錯誤
<?php
$database_server = "servername\databaseservername";
$database_port = "1433";
$database_authentication = "SQL Server";
$database_user = "username";
$database_password = "password";
$database_name = "DatabaseName";
$root = $_SERVER["DOCUMENT_ROOT"];
?>
<?php
require_once("includes/inc_files.php");
$current_page = "find";
$filter = coalesce($_GET["filter"], "Events");
$search = coalesce($_GET["search"], "");
$latitude = coalesce($_GET["latitude"], $_SESSION["latitude"], "");
$longitude = coalesce($_GET["longitude"], $_SESSION["longitude"], "");
if (!empty($latitude) && !isset($_SESSION["latitude"])) $_SESSION["latitude"] =
$latitude;
if (!empty($longitude) && !isset($_SESSION["longitude"])) $_SESSION["longitude"] =
$longitude;
$query = preg_replace("#[^a-z 0-9?!]#i", "", $search);
$do_search = false;
if ($filter == "Events" && !empty($latitude) && !empty($longitude)) {
$do_search = true;
$radius = 40;
$sql_columns = "
Events.ID AS eventid,
Events.VenueID AS venueid,
Events.Title AS title,
Events.EventDate AS date,
Venues.Name AS venue,
Venues.City AS city,
ROUND(dbo.GETDISTANCE(Venues.Lat, Venues.Lon, $latitude, $longitude, 'Miles'), 0) AS distance,
Venues.ImageName AS photo";
$sql_where = "
" . (!empty($search) ? "Events.Tags LIKE '%$query%' AND " : "") . "Events.EventDate >= GETDATE() AND CAST(CAST(Events.VenueID AS varchar(10)) AS bigint) IN (
SELECT ID
FROM LiveData
WHERE ROUND(dbo.GETDISTANCE(Lat, Lon, $latitude, $longitude, 'Miles'), 0) BETWEEN 0 AND $radius
)";
$sql = "
SELECT $sql_columns
FROM LiveData AS Events
INNER JOIN LiveData AS Venues ON CAST(CAST(Events.VenueID AS varchar(10)) AS bigint) = Venues.ID
WHERE $sql_where";
$query_recordsets = $database_mssql->query($sql);
$query_data = $query_recordsets[0];
$page = !empty($_GET["page"]) ? (int) $_GET["page"] : 1;
$per_page = 20;
$total_count = count($query_data);
$pagination = new Pagination($page, $per_page, $total_count);
$sql = "
SELECT *
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY Events.EventDate ASC) AS row,
$sql_columns
FROM LiveData AS Events
INNER JOIN LiveData AS Venues ON CAST(CAST(Events.VenueID AS varchar(10)) AS bigint) = Venues.ID
WHERE $sql_where
) AS a
WHERE row >= {$pagination->offset()} AND row < {$pagination->offset()} + $per_page";
$query_recordsets = $database_mssql->query($sql);
$query_data = $query_recordsets[0];
}
else if ($filter == "People") {
$do_search = true;
$sql = "
SELECT username,
first_name,
last_name,
country
FROM users
WHERE username LIKE '%$query%' OR CONCAT(first_name, ' ', last_name) LIKE '%$query%'";
$query_data = User::find_by_sql($sql);
$page = !empty($_GET["page"]) ? (int) $_GET["page"] : 1;
$per_page = 20;
$total_count = count($query_data);
$pagination = new Pagination($page, $per_page, $total_count);
$sql .= " LIMIT $per_page OFFSET {$pagination->offset()}";
$query_data = User::find_by_sql($sql);
}
?>
我在內部託管所有這些內容並將其推送到網絡上。當我在我的瀏覽器中使用localhost查看它時,我收到500內部服務器錯誤。
任何意見都會很棒!
事件日誌中的任何錯誤? –
您發佈了連接憑證增強版,但沒有用於連接的代碼。它是什麼? PDO?你可以將代碼添加到問題中嗎? – hek2mgl
對不起,我拖着另一個有優先權的項目。尤里·加蘭特,事件日誌中沒有錯誤。 @ hek2mgl,我會發布上面用於連接數據庫的代碼。 –