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