简体   繁体   中英

Connecting to a MSSQL database view with php

I've never worked with Views on MSSQL so I hope I'm note asking a dumb question.

I have a MSSQL database and I can easiliy retrieve information from it like:

mssql_query(SELECT tbDocs FROM tbServices);

But I can't get data from a view. For example there is a view named View_Technical_Service it gets fields from tbServices and tbCustomer. Whenever I execute a query from php like

mssql_query(SELECT tbDocs FROM View_Technical_Service);

I get a time out error msg from chrome:

Error 324 (net::ERR_EMPTY_RESPONSE):

So what's wrong? Is it not possible to get from a MSSQL View with php?

To answer the question, yes you can use views in the same way as tables - I do it frequently. But, you should use your DB Tool such as phpMyAdmin or SQLYog to determine if the view is working properly and that you can actually see the "view" as you expect - you should be able to look at the data exactly the same way as you would a table.

If you're using Chrome, there is apparently a rampant problem world wide with how it handles empty results, which also seems to verify that the View doesn't have, or is unable to show, any data to show you

Yes, it works. I have tested DSN less ODBC from PHP on a Windows Apache server. BUT When I used [Table Name] in the query string it DID NOT work. I had to remove the space (TableName). So I recommend removing spaces from table names and do not rely on [ ].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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