简体   繁体   English

使用php连接到MSSQL数据库视图

[英]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. 我从未在MSSQL上使用过Views,所以希望我注意到一个愚蠢的问题。

I have a MSSQL database and I can easiliy retrieve information from it like: 我有一个MSSQL数据库,可以像这样轻松地从中检索信息:

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. 例如,有一个名为View_Technical_Service的视图,它从tbServices和tbCustomer获取字段。 Whenever I execute a query from php like 每当我从php执行查询时

mssql_query(SELECT tbDocs FROM View_Technical_Service);

I get a time out error msg from chrome: 我从chrome收到超时错误消息:

Error 324 (net::ERR_EMPTY_RESPONSE):

So what's wrong? 那怎么了 Is it not possible to get from a MSSQL View with php? 使用php从MSSQL视图中获取是不可能的吗?

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. 但是,您应该使用诸如phpMyAdmin或SQLYog之类的数据库工具来确定视图是否正常运行,并且可以按预期实际看到“视图”-您应该能够以与您完全相同的方式查看数据将一张桌子。

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 如果您使用的是Chrome,那么全球范围内如何处理空结果显然存在着一个猖problem的问题,这似乎也可以验证View是否没有或无法显示任何可显示给您的数据

Yes, it works. 是的,它有效。 I have tested DSN less ODBC from PHP on a Windows Apache server. 我已经在Windows Apache服务器上测试了PHP的DSN较少的ODBC。 BUT When I used [Table Name] in the query string it DID NOT work. 但是,当我在查询字符串中使用[表名]时,它不会起作用。 I had to remove the space (TableName). 我必须删除空格(TableName)。 So I recommend removing spaces from table names and do not rely on [ ]. 因此,我建议从表名称中删除空格,并且不要依赖[]。

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

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