PHPBuilder - ODBC Socket Server Page 4

RSS Twitter

ODBC Socket Server - Page 4

by: Tim Uckun
December 6, 2000

Here is how you would use this object:


// 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 "";
$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 (!
"<p>There was an error : " $db->errorMsg() . "<p>";
} else {
// Simple iteration when you already know the field names
print "<table>";
    while (!

// 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>";
"<td>"$db->FIELD2 "</td>";
// What if you don't know the field names?
// go back to the beginning we could have moved backwards too!



while (!
    foreach (
$db->getFieldNames() as $fieldname) {
"<td>" $db->getField($fieldname) . "</td>";
// foreach
Print "</tr>";

// while
print "</table>";
Of course you are not limited to SELECT queries. Action queries (INSERT and UPDATE) obviously don't return a recordset, but they do return a true or false depending on how the engine handled them. Once again, if there are any errors present you can check the Error variable. You may also want to do some things with the XML variable. For example, you may want to send the raw XML to a client for B2B syndication.
Although this object was written to parse the MS ADO XML format, it could easily be rewritten to accommodate the native XML format of the socket server. In a future version, the socket server will be able to hand out either XML type on demand.
I hope this tutorial was useful to you. I want to thank the fine people at Team FXML for the ODBC Socket server and of course the fine people at PHP for providing such a useful development environment.
The socketserverobj include file is available below.
-- Tim

« Previous Page

Comment and Contribute

Your comment has been submitted and is pending approval.

Tim Uckun



(Maximum characters: 1200). You have characters left.