-1

我在 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 内部服务器错误。

任何建议都会很棒!

4

1 回答 1

0

Just to add an answer to this thread, it looks like IIS and MSSQL 2012 were installed incorrectly. There was a conflict with the database port as well. MySQL and MSSQL were both using port 1433.

于 2013-01-09T15:14:21.963 回答