0

我可以很好地查询 SQL 服务器数据库。当我尝试查询视图时会出现问题。

我不想做任何疯狂的事情:

 $sql = 'select * from location_v';
 $stj = $db_destination->prepare($sql);

它一直在准备线上死去。这是我要回来的(这并不是那么有用):

DBD::ODBC::db prepare failed: (DBD: st_prepare/SQLPrepare err=-1)

视图不应该与表格完全相同吗?提前致谢。

4

3 回答 3

3

Did you try using the dbo. prefix on the view name (SELECT * FROM dbo.location_v)? Did you check that the view is actually in the dbo. schema? Did you check permissions on the view and/or the base table(s) the view is selecting from? Sadly ODBC does not give a very meaningful error message here, so it could be any number of things, but it is most likely either object not found (because of the prefix, or you are in the wrong database) or permissions.

于 2009-11-26T21:11:53.080 回答
1

Yes, views should be indistinguishable from tables for that query.

Can you actually query the view (rather than just the database in general)?

An error code of -1 is not strongly indicative of anything specific as a problem. It can sometimes be 'no permission', but it could be almost anything.

I suggest looking to see where the problem is by using DBI_TRACE=9 (or maybe smaller numbers) set in the environment (or use $dbh->trace(9)). This should give you lots of information (not all of it comprehensible) about what is going on; it may show you where the trouble actually is.

于 2009-11-26T21:12:31.727 回答
0

精氨酸。我发现了问题。在查询视图之前我有一些查询,并且在打开新视图之前我没有关闭我的句柄。在我运行查询之前,我需要做的就是:

undef $stj;

希望这对其他人有帮助。

于 2009-11-27T14:07:54.170 回答