我在Windows 2012服务器上使用SQL 2012中的数据库。我在代码中使用连接字符串连接到它时遇到了一些麻烦。我已经通过网络对其进行了测试并使用Visual Basic和Excel连接到它而没有任何问题。我很难过,因为我无法连接它,它与我的代码有关,我很确定。额外的一双眼睛会有所帮助。
<?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内部服务器错误。
任何建议都很棒!
答案 0 :(得分:0)
只是为这个帖子添加一个答案,看起来IIS和MSSQL 2012安装不正确。与数据库端口也存在冲突。 MySQL和MSSQL都使用端口1433。