72c751da |
1 | <?php |
72c751da |
2 | |
b68275d5 |
3 | /** |
4 | * odbc.php - This is the ODBC Socket Server class PHP client class |
5 | * with sample usage at bottom. |
6 | * |
7 | * Released into the public domain for version 0.90 of ODBC Socket Server |
8 | * {@link http://odbc.linuxbox.com/} |
ce02a9bf |
9 | * |
10 | * @package moodlecore |
b68275d5 |
11 | * @author Team FXML |
12 | * @copyright Copyright (c) 1999 Team FXML |
13 | * @license http://odbc.linuxbox.com/ public domain |
b68275d5 |
14 | */ |
15 | |
ce02a9bf |
16 | /** |
b68275d5 |
17 | * ODBC Socket Server class |
ce02a9bf |
18 | * |
19 | * @package moodlecore |
20 | * @copyright Copyright (c) 1999 Team FXML |
21 | * @license http://odbc.linuxbox.com/ public domain |
b68275d5 |
22 | */ |
72c751da |
23 | class ODBCSocketServer { |
72c751da |
24 | |
b68275d5 |
25 | /** |
26 | * Name of the host to connect to |
27 | * @var string $sHostName |
28 | */ |
29 | var $sHostName; |
30 | /** |
31 | * Port to connect to |
32 | * @var int $nPort |
33 | */ |
34 | var $nPort; |
35 | /** |
36 | * Connection string to use |
37 | * @var string $sConnectionString |
38 | */ |
39 | var $sConnectionString; |
40 | |
41 | // |
42 | /** |
43 | * Function to parse the SQL |
44 | * |
45 | * @param string $sSQL The SQL statement to parse |
46 | * @return string |
47 | */ |
72c751da |
48 | function ExecSQL($sSQL) { |
49 | |
50 | $fToOpen = fsockopen($this->sHostName, $this->nPort, &$errno, &$errstr, 30); |
51 | if (!$fToOpen) |
52 | { |
53 | //contruct error string to return |
54 | $sReturn = "<?xml version=\"1.0\"?>\r\n<result state=\"failure\">\r\n<error>$errstr</error>\r\n</result>\r\n"; |
55 | } |
56 | else |
57 | { |
58 | //construct XML to send |
59 | //search and replace HTML chars in SQL first |
60 | $sSQL = HTMLSpecialChars($sSQL); |
61 | $sSend = "<?xml version=\"1.0\"?>\r\n<request>\r\n<connectionstring>$this->sConnectionString</connectionstring>\r\n<sql>$sSQL</sql>\r\n</request>\r\n"; |
b68275d5 |
62 | //write request |
72c751da |
63 | fputs($fToOpen, $sSend); |
64 | //now read response |
65 | while (!feof($fToOpen)) |
66 | { |
67 | $sReturn = $sReturn . fgets($fToOpen, 128); |
68 | } |
69 | fclose($fToOpen); |
70 | } |
71 | return $sReturn; |
72 | } |
73 | }//class |
74 | ?> |