无法使用PHP PDO在MS Access数据库中查询已保存的查询

时间:2022-11-09 15:39:26

I have a Microsoft Access database with a bunch of saved queries. I would like to use PHP to run and grab the results of these queries. I can query tables in the same database just fine. My understanding is that I can treat queries as if they were tables.

我有一个Microsoft Access数据库与一堆保存的查询。我想使用PHP来运行并获取这些查询的结果。我可以在同一个数据库中查询表格。我的理解是,我可以将查询视为表格。

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? I'm fairly new to this. I appreciate any and all help! I will be happy to provide any additional information needed.

有没有办法让我用PHP获取MS Access中保存查询的结果?我对此很新。我感谢任何和所有的帮助!我很乐意提供所需的任何其他信息。

1 个解决方案

#1


0  

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); and changed

我添加了$ db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);并改变了

$results = $sth->fetchALL(PDO::FETCH_ASSOC); to $row = $sth->fetch(PDO::FETCH_ASSOC)

$ results = $ sth-> fetchALL(PDO :: FETCH_ASSOC);到$ row = $ sth-> fetch(PDO :: FETCH_ASSOC)

#1


0  

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); and changed

我添加了$ db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);并改变了

$results = $sth->fetchALL(PDO::FETCH_ASSOC); to $row = $sth->fetch(PDO::FETCH_ASSOC)

$ results = $ sth-> fetchALL(PDO :: FETCH_ASSOC);到$ row = $ sth-> fetch(PDO :: FETCH_ASSOC)