问题
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. Here is the error statement that shows up from php:
Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'Issues'. (severity 16) in /srv/www/htdocs/agreement.php on line 47
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
Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 48
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
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
Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 51
Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 52
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.
回答1:
Check that you're querying the right database or schema.
software.software_dbo.ApplicationInfo
means:
- 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
Perhaps check what the value of DBO
, amongst the other arguments, is in this statement: $connect = mssql_connect(DBSERVER, DBO, DBPW)
回答2:
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'
来源:https://stackoverflow.com/questions/2958395/why-is-my-sql-server-query-failing