TYPO3 CMS  TYPO3_7-6
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());
$database
Definition: server.php:40
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
_rs2serialize(&$rs, $conn=false, $sql='')
err($s)
Definition: server.php:49
undomq(&$m)
Definition: server.php:55
$remote
Definition: server.php:70
$conn
Definition: server.php:81
$sep
Definition: server.php:44
$pwd
Definition: server.php:39
$driver
Definition: server.php:36
$uid
Definition: server.php:38
$host
Definition: server.php:37
$ACCEPTIP
Definition: server.php:31
$sql
Definition: server.php:84