/[informatika.old]/html/odbc.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /html/odbc.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Wed Apr 5 14:01:16 2000 UTC (23 years, 11 months ago) by dpavlin
Branch: PLIVA
CVS Tags: R0
Changes since 1.1: +0 -0 lines
početni import


1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
2 <HTML lang="en">
3 <HEAD>
4 <TITLE>PHP&nbsp;Test</TITLE>
5 <META name="author" content="TeamFXML">
6 <META name="copyright" content="Team FXML">
7 <META name="description" content="This page description.">
8 <META name="keywords" content="insert, your, keywords">
9 </HEAD>
10 <BODY>
11 <?
12 //This is the ODBC Socket Server class PHP client class with sample usage
13 // at bottom.
14 // (c) 1999 Team FXML
15 // Released into the public domain for version 0.90 of ODBC Socket Server
16 // http://odbc.linuxbox.com/
17
18 class ODBCSocketServer {
19 var $sHostName; //name of the host to connect to
20 var $nPort; //port to connect to
21 var $sConnectionString; //connection string to use
22
23 //function to parse the SQL
24 function ExecSQL($sSQL) {
25
26 $fToOpen = fsockopen($this->sHostName, $this->nPort, &$errno, &$errstr, 30);
27 if (!$fToOpen)
28 {
29 //contruct error string to return
30 $sReturn = "<?xml version=\"1.0\"?>\r\n<result state=\"failure\">\r\n<error>$errstr</error>\r\n</result>\r\n";
31 }
32 else
33 {
34 //construct XML to send
35 //search and replace HTML chars in SQL first
36 $sSQL = HTMLSpecialChars($sSQL);
37 $sSend = "<?xml version=\"1.0\"?>\r\n<request>\r\n<connectionstring>$this->sConnectionString</connectionstring>\r\n<sql>$sSQL</sql>\r\n</request>\r\n";
38 //write request
39 fputs($fToOpen, $sSend);
40 //now read response
41 while (!feof($fToOpen))
42 {
43 $sReturn = $sReturn . fgets($fToOpen, 128);
44 }
45 fclose($fToOpen);
46 }
47 return $sReturn;
48 }
49 }//class
50
51 //Here is the code that uses this class. First we create the class
52 $oTest = new ODBCSocketServer;
53
54 //Set the Hostname, port, and connection string
55 $oTest->sHostName = "netmon.pliva.hr";
56 $oTest->nPort = 9628;
57 $oTest->sConnectionString = "DSN=imenik;UID=administrator;PWD=;";
58
59 //now exec the SQL
60 $sResult = $oTest->ExecSQL("SELECT * FROM kontakti");
61
62 //now format and print the results. Subsititute in your code here!
63 //We will use the PHP XML Parser module to parse the result :)
64 //to use the parser, remember to compile PHP with the --with-xml option
65 //see the PHP manual for more info and specific examples
66
67 //For this example, we will print the results in table form
68 //and then print the raw XML string
69
70 //Here will be the XML handlers we will use
71
72 //Handler for starting elements
73 function startElement($parser, $name, $attribs)
74 {
75 if (strtolower($name) == "row")
76 {
77 //handler for the row element
78 print "<tr>";
79 }
80 if (strtolower($name) == "column")
81 {
82 //handler for the column
83 print "<td>";
84 }
85 if (strtolower($name) == "error")
86 {
87 //handler for the error
88 print "<tr><td>";
89 }
90 if (strtolower($name) == "result")
91 {
92 print "Table of Results: <br><table border=1>";
93 }
94 }
95
96 //handler for the end of elements
97 function endElement($parser, $name)
98 {
99 if (strtolower($name) == "row")
100 {
101 //handler for the row element
102 print "</tr>";
103 }
104 if (strtolower($name) == "column")
105 {
106 //handler for the column
107 print "</td>";
108 }
109 if (strtolower($name) == "error")
110 {
111 //handler for the error
112 print "</td></tr>";
113 }
114 if (strtolower($name) == "result")
115 {
116 print "</table> <br>End Of Results<br>";
117 }
118 }
119
120 //handler for character data
121 function characterData($parser, $data)
122 {
123 print "$data";
124 }
125
126
127 //parse the XML
128 $xml_parser = xml_parser_create();
129 xml_set_element_handler($xml_parser, "startElement", "endElement");
130 xml_set_character_data_handler($xml_parser, "characterData");
131
132 if (!xml_parse($xml_parser, $sResult)) {
133 die(sprintf("XML error: %s at line %d",
134 xml_error_string(xml_get_error_code($xml_parser)),
135 xml_get_current_line_number($xml_parser)));
136 }
137 else
138 {
139 echo("Successful XML parse. ");
140 }
141
142 print "Raw data results: <br>";
143 xml_parser_free($xml_parser);
144
145 $sResult = HtmlSpecialChars($sResult);
146 echo("<pre>");
147 echo($sResult);
148 echo("</pre>");
149
150 ?>
151
152 </BODY>
153 </HTML>
154

  ViewVC Help
Powered by ViewVC 1.1.26