]> git.openstreetmap.org Git - nominatim.git/blob - lib/db.php
clean up docs for lookup call
[nominatim.git] / lib / db.php
1 <?php
2
3 require_once('DB.php');
4
5
6 function &getDB($bNew = false, $bPersistent = false)
7 {
8     // Get the database object
9     $oDB = chksql(
10         DB::connect(CONST_Database_DSN.($bNew?'?new_link=true':''), $bPersistent),
11         'Failed to establish database connection'
12     );
13     $oDB->setFetchMode(DB_FETCHMODE_ASSOC);
14     $oDB->query("SET DateStyle TO 'sql,european'");
15     $oDB->query("SET client_encoding TO 'utf-8'");
16     $iMaxExecution = ini_get('max_execution_time') * 1000;
17     if ($iMaxExecution > 0) $oDB->query("SET statement_timeout TO $iMaxExecution");
18     return $oDB;
19 }
20
21 function getDBQuoted($s)
22 {
23     return "'".pg_escape_string($s)."'";
24 }
25
26 function getArraySQL($a)
27 {
28     return 'ARRAY['.join(',', $a).']';
29 }
30
31 function getPostgresVersion(&$oDB)
32 {
33     $sVersionString = $oDB->getOne('select version()');
34     preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[^0-9]#', $sVersionString, $aMatches);
35     return (float) ($aMatches[1].'.'.$aMatches[2]);
36 }
37
38 function getPostgisVersion(&$oDB)
39 {
40     $sVersionString = $oDB->getOne('select postgis_full_version()');
41     preg_match('#POSTGIS="([0-9]+)[.]([0-9]+)[.]([0-9]+)( r([0-9]+))?"#', $sVersionString, $aMatches);
42     return (float) ($aMatches[1].'.'.$aMatches[2]);
43 }