source: trunk/admin/include/functions_install.inc.php @ 4410

Last change on this file since 4410 was 4410, checked in by nikrou, 14 years ago

Feature 1255 :

  • add postgres database engine
  • change installation process to allow postgres or mysql database
File size: 3.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * loads an sql file and executes all queries
26 *
27 * Before executing a query, $replaced is... replaced by $replacing. This is
28 * useful when the SQL file contains generic words. Drop table queries are
29 * not executed.
30 *
31 * @param string filepath
32 * @param string replaced
33 * @param string replacing
34 * @return void
35 */
36function execute_sqlfile($filepath, $replaced, $replacing)
37{
38  $sql_lines = file($filepath);
39  $query = '';
40  foreach ($sql_lines as $sql_line)
41  {
42    $sql_line = trim($sql_line);
43    if (preg_match('/(^--|^$)/', $sql_line))
44    {
45      continue;
46    }
47    $query.= ' '.$sql_line;
48    // if we reached the end of query, we execute it and reinitialize the
49    // variable "query"
50    if (preg_match('/;$/', $sql_line))
51    {
52      $query = trim($query);
53      $query = str_replace($replaced, $replacing, $query);
54      // we don't execute "DROP TABLE" queries
55      if (!preg_match('/^DROP TABLE/i', $query))
56      {
57        global $install_charset_collate;
58        if ( !empty($install_charset_collate) )
59        {
60          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
61          {
62            $query = $matches[1].' '.$install_charset_collate.';';
63          }
64        }
65        pwg_query($query);
66      }
67      $query = '';
68    }
69  }
70}
71
72/**
73 * Search for database engines available
74 *
75 * We search for functions_DATABASE_ENGINE.inc.php
76 * and we check if the connect function for that database exists
77 *
78 * @return array
79 */
80function available_engines()
81{
82  $engines = array();
83
84  $pattern = PHPWG_ROOT_PATH. 'include/dblayer/functions_%s.inc.php';
85  include_once PHPWG_ROOT_PATH. 'include/dblayer/dblayers.inc.php';
86
87  foreach ($dblayers as $engine_name => $engine)
88  {
89    if (file_exists(sprintf($pattern, $engine_name)) 
90        && function_exists($engine['function_available']))
91    {
92      $engines[$engine_name] = $engine['engine'];
93    }
94  }
95 
96  return $engines;
97}
98?>
Note: See TracBrowser for help on using the repository browser.