为什么我的 SQL Server 查询失败? [英] Why is my SQL Server query failing?
问题描述
connect();
$arr = mssql_fetch_assoc(mssql_query("SELECT Applications.ProductName,
Applications.ProductVersion, Applications.ProductSize,
Applications.Description, Applications.ProductKey, Applications.ProductKeyID,
Applications.AutomatedInstaller, Applications.AutomatedInstallerName,
Applications.ISO, Applications.ISOName, Applications.Internet,
Applications.InternetURL, Applications.DatePublished, Applications.LicenseID,
Applications.InstallationGuide, Vendors.VendorName
FROM Applications
INNER JOIN Vendors ON Applications.VendorID = Vendors.VendorID
WHERE ApplicationID = ".$ApplicationID));
$query1 = mssql_query("SELECT Issues.AppID, Issues.KnownIssues
FROM Issues
WHERE Issues.AppID=".$ApplicationID);
$issues = mssql_fetch_assoc($query1);
$query2 = mssql_query("SELECT ApplicationInfo.AppID,
ApplicationInfo.Support_Status, ApplicationInfo.UD_Training,
ApplicationInfo.AtomicTraining, ApplicationInfo.VendorURL
FROM ApplicationInfo
WHERE ApplicationInfo.AppID = ".$ApplicationID);
$row = mssql_fetch_assoc($query2);
function connect(){
$connect = mssql_connect(DBSERVER, DBO, DBPW) or
die("Unable to connect to server");
$selected = mssql_select_db(DBNAME, $connect) or
die("Unable to connect to database");
return $connect;
}
上面是代码.第一个 query/fetch_assoc 工作得很好,但是接下来的 2 个查询失败了,我不知道为什么.这是从 php 显示的错误语句:
Above is the code. The first query/fetch_assoc works perfectly fine, however the next 2 queries fail and I cannot figure out why. Here is the error statement that shows up from php:
警告:mssql_query() [function.mssql-query]:消息:对象名称问题"无效.(严重性 16)在/srv/www/htdocs/agreement.php 第 47 行
Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'Issues'. (severity 16) in /srv/www/htdocs/agreement.php on line 47
警告:mssql_query() [function.mssql-query]:一般 SQL Server 错误:在第 47 行的/srv/www/htdocs/agreement.php 中检查来自 SQL Server 的消息(严重性 16)警告:mssql_query() [function.mssql-query]:第 47 行/srv/www/htdocs/agreement.php 中的查询失败
Warning: mssql_query() [function.mssql-query]: General SQL Server error: Check messages from the SQL Server (severity 16) in /srv/www/htdocs/agreement.php on line 47 Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 47
警告:mssql_fetch_assoc():在第 48 行的/srv/www/htdocs/agreement.php 中,提供的参数不是有效的 MS SQL 结果资源
Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 48
警告:mssql_query() [function.mssql-query]:消息:无效的对象名称software.software_dbo.ApplicationInfo".(严重性 16)在/srv/www/htdocs/agreement.php 第 51 行
Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'software.software_dbo.ApplicationInfo'. (severity 16) in /srv/www/htdocs/agreement.php on line 51
警告:mssql_query() [function.mssql-query]:一般 SQL Server 错误:在第 51 行的/srv/www/htdocs/agreement.php 中检查来自 SQL Server 的消息(严重性 16)
Warning: mssql_query() [function.mssql-query]: General SQL Server error: Check messages from the SQL Server (severity 16) in /srv/www/htdocs/agreement.php on line 51
警告:mssql_query() [function.mssql-query]:第 51 行/srv/www/htdocs/agreement.php 中的查询失败
Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 51
警告:mssql_fetch_assoc():在第 52 行的/srv/www/htdocs/agreement.php 中,提供的参数不是有效的 MS SQL 结果资源
Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 52
该错误显然集中在查询未执行这一事实上.在我的数据库中,我有一个名为 Issues 的表和一个名为 ApplicationInfo 的表,所以我不确定为什么它告诉我它们是无效对象.
The error clearly centers around the fact that the query is not executing. In my database I have a table called Issues and a table called ApplicationInfo so I am unsure why it is telling me that they are invalid objects.
推荐答案
检查您查询的数据库或架构是否正确.
Check that you're querying the right database or schema.
software.software_dbo.ApplicationInfo
表示:
- 名为
software
的数据库 - 一个名为
software_dbo
的架构 - 可能是这个问题.可能是 SQL Server 上的dbo
. - 一个名为
ApplicationInfo
的视图/表
- a database named
software
- a schema named
software_dbo
- likely this is the problem. Likely isdbo
on your SQL Server. - a view/table named
ApplicationInfo
也许检查一下 DBO
的值,以及其他参数,在这个语句中:$connect = mssql_connect(DBSERVER, DBO, DBPW)
Perhaps check what the value of DBO
, amongst the other arguments, is in this statement: $connect = mssql_connect(DBSERVER, DBO, DBPW)
这篇关于为什么我的 SQL Server 查询失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!