#native_company# #native_desc#
#native_cta#

ODBC Socket Server Page 4

By Tim Uckun
on December 6, 2000

Here is how you would use this object:

<?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>";

        

?>



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

1
|
2
|
3
|
4