我正在使用PHP读取一个mdb文件,本地服务器如下:
<?php
$myapp = new COM("word.application");
$conn = new COM("ADODB.Connection") or die("Oops!");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:Usersadmin.mdb","","password");
$data = $conn->Execute("SELECT * FROM TFTemp17");
print "<TABLE border='1'>print "<tr>";
print $data[4];
print "</tr>";
echo "</TABLE>";
?>
在这个mbd文件中,a有一个包含行和列的表,所以直到我只读取第一行和我想要的列,但我不知道如何读取第二行。我想要的是在某一行上读某一列(而不仅仅是第一行),我怎么能做到呢?
您必须循环遍历从ADO执行行中提取的记录集。参见PHP COM手册:
$conn = new COM("ADODB.Connection") or die("Oops!");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:Usersadmin.mdb","","password");
$data = $conn->Execute("SELECT * FROM TFTemp17");
echo "<TABLE border='1'>";
echo "<tr>";
$num_columns = $data->Fields->Count();
while (!$data->EOF) {
for ($i=0; $i < $num_columns; $i++) {
echo "<td>".$data->Fields($i)->value."</td>";
}
$data->MoveNext();
}
echo "</tr>";
echo "</TABLE>";
$data->Close();
$conn->Close();
$data = null;
$conn = null;