[英]Cannot query with PHP PDO a saved query in MS Access Database
I have a Microsoft Access database with a bunch of saved queries. 我有一个Microsoft Access数据库与一堆保存的查询。 I would like to use PHP to run and grab the results of these queries. 我想使用PHP来运行并获取这些查询的结果。 I can query tables in the same database just fine. 我可以在同一个数据库中查询表格。 My understanding is that I can treat queries as if they were tables. 我的理解是,我可以将查询视为表格。
This will return data from the table "New Grower Fields" just fine: 这将从“New Grower Fields”表返回数据就好了:
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$connString; SystemDB=$mdw; Uid=$username; Pwd=$password");
$sth = $db->prepare("SELECT * FROM [New Grower Fields]");
$sth->execute();
$results = $sth->fetchALL(PDO::FETCH_ASSOC);
print_r($results);
But if I want to use a saved query, which I believe should act just like querying a table, I don't get anything. 但是,如果我想使用一个保存的查询,我相信它应该像查询表一样,我什么也得不到。
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$connString; SystemDB=$mdw; Uid=$username; Pwd=$password");
$sth = $db->prepare("SELECT * FROM [Daily Tonnage by Plant]");
$sth->execute();
$results = $sth->fetchALL(PDO::FETCH_ASSOC);
print_r($results);
Is there any way to allow me to get the results of a saved query in MS Access with PHP? 有没有办法让我用PHP获取MS Access中保存查询的结果? I'm fairly new to this. 我对此很新。 I appreciate any and all help! 我感谢任何和所有的帮助! I will be happy to provide any additional information needed. 我很乐意提供所需的任何其他信息。
This seemed to solve it for me: 这似乎解决了我:
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$connString; SystemDB=$mdw; Uid=$username; Pwd=$password");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $db->prepare("SELECT [Grade Date], NetWt FROM [Daily Tonnage by Plant]");
$sth->execute();
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
I added $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
我添加了$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
and changed 并改变了
$results = $sth->fetchALL(PDO::FETCH_ASSOC);
to $row = $sth->fetch(PDO::FETCH_ASSOC)
to $row = $sth->fetch(PDO::FETCH_ASSOC)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.