What are the best practices for connecting to and querying multiple MS MDB files in PHP?

When connecting to and querying multiple MS MDB files in PHP, it is best to use the ODBC extension to establish a connection to each database file separately. By creating individual connections for each MDB file, you can query them independently and efficiently. Additionally, it is recommended to use parameterized queries to prevent SQL injection attacks and ensure data security.

// Connect to the first MDB file
$dsn1 = "Driver={Microsoft Access Driver (*.mdb)};Dbq=path/to/first.mdb";
$user = "";
$password = "";
$conn1 = odbc_connect($dsn1, $user, $password);

// Connect to the second MDB file
$dsn2 = "Driver={Microsoft Access Driver (*.mdb)};Dbq=path/to/second.mdb";
$conn2 = odbc_connect($dsn2, $user, $password);

// Query the first MDB file
$query1 = "SELECT * FROM table1";
$result1 = odbc_exec($conn1, $query1);

// Query the second MDB file
$query2 = "SELECT * FROM table2";
$result2 = odbc_exec($conn2, $query2);

// Fetch and process results
while ($row = odbc_fetch_array($result1)) {
    // Process data from the first MDB file
}

while ($row = odbc_fetch_array($result2)) {
    // Process data from the second MDB file
}

// Close connections
odbc_close($conn1);
odbc_close($conn2);