ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

server.php
Go to the documentation of this file.
1 <?php
2 
12 /* Documentation on usage is at http://php.weblogs.com/adodb_csv
13  *
14  * Legal query string parameters:
15  *
16  * sql = holds sql string
17  * nrows = number of rows to return
18  * offset = skip offset rows of data
19  * fetch = $ADODB_FETCH_MODE
20  *
21  * example:
22  *
23  * http://localhost/php/server.php?select+*+from+table&nrows=10&offset=2
24  */
25 
26 
27 /*
28  * Define the IP address you want to accept requests from
29  * as a security measure. If blank we accept anyone promisciously!
30  */
31 $ACCEPTIP = '127.0.0.1';
32 
33 /*
34  * Connection parameters
35  */
36 $driver = 'mysql';
37 $host = 'localhost'; // DSN for odbc
38 $uid = 'root';
39 $pwd = 'garbase-it-is';
40 $database = 'test';
41 
42 /*============================ DO NOT MODIFY BELOW HERE =================================*/
43 // $sep must match csv2rs() in adodb.inc.php
44 $sep = ' :::: ';
45 
46 include('./adodb.inc.php');
47 include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
48 
49 function err($s)
50 {
51  die('**** '.$s.' ');
52 }
53 
54 // undo stupid magic quotes
55 function undomq(&$m)
56 {
57  if (get_magic_quotes_gpc()) {
58  // undo the damage
59  $m = str_replace('\\\\','\\',$m);
60  $m = str_replace('\"','"',$m);
61  $m = str_replace('\\\'','\'',$m);
62 
63  }
64  return $m;
65 }
66 
68 
69 
70 $remote = $_SERVER["REMOTE_ADDR"];
71 
72 
73 if (!empty($ACCEPTIP))
74  if ($remote != '127.0.0.1' && $remote != $ACCEPTIP)
75  err("Unauthorised client: '$remote'");
76 
77 
78 if (empty($_REQUEST['sql'])) err('No SQL');
79 
80 
81 $conn = ADONewConnection($driver);
82 
83 if (!$conn->Connect($host,$uid,$pwd,$database)) err($conn->ErrorNo(). $sep . $conn->ErrorMsg());
84 $sql = undomq($_REQUEST['sql']);
85 
86 if (isset($_REQUEST['fetch']))
87  $ADODB_FETCH_MODE = $_REQUEST['fetch'];
88 
89 if (isset($_REQUEST['nrows'])) {
90  $nrows = $_REQUEST['nrows'];
91  $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : -1;
92  $rs = $conn->SelectLimit($sql,$nrows,$offset);
93 } else
94  $rs = $conn->Execute($sql);
95 if ($rs){
96  //$rs->timeToLive = 1;
98  $rs->Close();
99 } else
100  err($conn->ErrorNo(). $sep .$conn->ErrorMsg());
$host
$host
Definition: server.php:37
$database
$database
Definition: server.php:40
undomq
undomq(&$m)
Definition: server.php:55
$rs
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
$sql
$sql
Definition: server.php:84
$ADODB_FETCH_MODE
$ADODB_FETCH_MODE
Definition: functions_db.inc.php:70
err
err($s)
Definition: server.php:49
_rs2serialize
_rs2serialize(&$rs, $conn=false, $sql='')
Definition: adodb-csvlib.inc.php:36
$pwd
$pwd
Definition: server.php:39
$remote
$remote
Definition: server.php:70
$sep
$sep
Definition: server.php:44
$conn
$conn
Definition: server.php:81
$uid
$uid
Definition: server.php:38
$driver
$driver
Definition: server.php:36
$ACCEPTIP
$ACCEPTIP
Definition: server.php:31