简体   繁体   English

为什么我的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;
}

Above is the code. 上面是代码。 The first query/fetch_assoc works perfectly fine, however the next 2 queries fail and I cannot figure out why. 第一个查询/ fetch_assoc工作正常,但是接下来的两个查询失败,我无法弄清原因。 Here is the error statement that shows up from php: 这是从php显示的错误声明:

Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'Issues'. 警告:mssql_query()[function.mssql-query]:消息:无效的对象名称“问题”。 (severity 16) in /srv/www/htdocs/agreement.php on line 47 (严重性16)在第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_query()[function.mssql-query]:常规SQL Server错误:在第47行的/srv/www/htdocs/agreement.php中检查来自SQL Server(严重性16)的消息警告:mssql_query()[函数。 [mssql-query]:在第47行的/srv/www/htdocs/agreement.php中查询失败

Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 48 警告:mssql_fetch_assoc():在第48行的/srv/www/htdocs/agreement.php中,提供的参数不是有效的MS SQL结果资源

Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'software.software_dbo.ApplicationInfo'. 警告:mssql_query()[function.mssql-query]:消息:无效的对象名'software.software_dbo.ApplicationInfo'。 (severity 16) in /srv/www/htdocs/agreement.php on line 51 (严重性16)在第51行的/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 51 警告:mssql_query()[function.mssql-query]:常规SQL Server错误:在第51行的/srv/www/htdocs/agreement.php中检查来自SQL Server(严重性16)的消息

Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 51 警告:mssql_query()[function.mssql-query]:在/srv/www/htdocs/agreement.php的第51行查询失败

Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 52 警告:mssql_fetch_assoc():提供的参数不是/srv/www/htdocs/agreement.php中第52行上的有效MS SQL结果资源

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. 在我的数据库中,我有一个名为Issues的表和一个名为ApplicationInfo的表,所以我不确定为什么它告诉我它们是无效的对象。

Check that you're querying the right database or schema. 检查您正在查询正确的数据库或架构。

software.software_dbo.ApplicationInfo means: software.software_dbo.ApplicationInfo意思是:

  • a database named software 一个名为software的数据库
  • a schema named software_dbo - likely this is the problem . 一个名为software_dbo的模式- 可能是问题所在 Likely is dbo on your SQL Server. 可能是SQL Server上的dbo
  • a view/table named ApplicationInfo 一个名为ApplicationInfo的视图/表

Perhaps check what the value of DBO , amongst the other arguments, is in this statement: $connect = mssql_connect(DBSERVER, DBO, DBPW) 也许检查一下此语句中DBO的值以及其他参数: $connect = mssql_connect(DBSERVER, DBO, DBPW)

Check to see that the user you are connecting with has permission to use the tables you are trying to query. 检查与您连接的用户是否有权使用您要查询的表。 Seams like the issue is that the tables cannot be found. 像问题这样的接缝是找不到表。

The best way to handle this would be to grant the user permssions to all objects in that database: 处理此问题的最佳方法是将用户权限授予该数据库中的所有对象:

GRANT SELECT, INSERT, DELETE <any other permissions that user needs> ON `database`.`*` TO `user`@`localhost` IDENTIFIED BY 'password'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM