Using Tims code for the odbc socket server i am able to query a access 97 database. I am having problems when i do more complex queries. When i do a join query and have to indentical field names but different tables i cant figure out how to access the 2nd variable.
select a.field1, b.field1 from a as table1, b as table2 where .......
$db->a.FIELD1 // wont work
$db->FIELD1 // will work but only will show first result not b.field1
Any ideas on how to go about this or is there a better class to use?
http://www.phpbuilder.com/columns/timuckun20001207.php3
<?php
// Of course we have to include the file.
include ("socketserverobj.php");
// First we create the class
$db = new ODBCSocketServer;
// Set the Hostname, port, and connection string
$db->HostName = "192.168.0.4";
$db->Port = 9628;
// any valid ADO connection string should be fine. I find it easier just to set up the DSN
// and pass in the user info
$db->ConnectionString = "DSN=Some_ODBC_DSN;UID=Some_User;PWD=Some_Password;";
//now execute the SQL
$result = $db->execute("Select Field1, field2 from SomeTable");
if (!$result){
print "<p>There was an error : " . $db->errorMsg() . "<p>";
} else {
// Simple iteration when you already know the field names
print "<table>";
while (!$db->EOF){
Print "<tr>";
// the case folding is true by default
// this means we have to use upper case when accessing field names.
// If case folding was false then we would have to use exact case like this
// $db->Field1 , $db->field2
// or use getField method (see next example)
print "<td>". $db->FIELD1. "</td>";
print "<td>". $db->FIELD2 . "</td>";
Print "</tr>";
$db->moveNext();
}
print "</table>";
// What if you don't know the field names?
// go back to the beginning we could have moved backwards too!
$db->moveFirst();
print "<table>";
while (!$db->EOF){
Print "<tr>";
foreach ($db->getFieldNames() as $fieldname) {
Print "<td>" . $db->getField($fieldname) . "</td>";
} // foreach
Print "</tr>";
$db->moveNext();
} // while
print "</table>";
?>