1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2010 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 | */ |
---|
36 | function 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 | */ |
---|
80 | function 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 | { |
---|
91 | $engines[$engine_name]['label'] = $engine['engine']; |
---|
92 | $engines[$engine_name]['available'] = false; |
---|
93 | |
---|
94 | if (isset($engine['function_available']) |
---|
95 | && function_exists($engine['function_available'])) |
---|
96 | { |
---|
97 | $engines[$engine_name]['available'] = true; |
---|
98 | } |
---|
99 | elseif (isset($engine['class_available']) |
---|
100 | && class_exists($engine['class_available'])) |
---|
101 | { |
---|
102 | $engines[$engine_name]['available'] = true; |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if ($engines['sqlite']['available'] && $engines['pdo-sqlite']['available']) |
---|
108 | { |
---|
109 | if ($GLOBALS['conf']['db_sqlite_default']=='native') |
---|
110 | { |
---|
111 | unset($engines['pdo-sqlite']); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | unset($engines['sqlite']); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | return $engines; |
---|
120 | } |
---|
121 | ?> |
---|