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