@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | case 'datetime': |
| 213 | 213 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
| 214 | - return 'to_timestamp('. |
|
| 215 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
| 214 | + return 'to_timestamp(' . |
|
| 215 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
| 216 | 216 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 217 | 217 | else |
| 218 | 218 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -764,10 +764,10 @@ discard block |
||
| 764 | 764 | $returning = ''; |
| 765 | 765 | $with_returning = false; |
| 766 | 766 | // lets build the returning string, mysql allow only in normal mode |
| 767 | - if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 767 | + if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 768 | 768 | { |
| 769 | 769 | // we only take the first key |
| 770 | - $returning = ' RETURNING '.$keys[0]; |
|
| 770 | + $returning = ' RETURNING ' . $keys[0]; |
|
| 771 | 771 | $with_returning = true; |
| 772 | 772 | } |
| 773 | 773 | |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 799 | 799 | VALUES |
| 800 | 800 | ' . implode(', |
| 801 | - ', $insertRows).$replace.$returning, |
|
| 801 | + ', $insertRows) . $replace . $returning, |
|
| 802 | 802 | array( |
| 803 | 803 | 'security_override' => true, |
| 804 | 804 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | if ($returnmode === 2) |
| 812 | 812 | $return_var = array(); |
| 813 | 813 | |
| 814 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 814 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 815 | 815 | { |
| 816 | 816 | if (is_numeric($row[0])) // try to emulate mysql limitation |
| 817 | 817 | { |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -59,11 +60,13 @@ discard block |
||
| 59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 60 | 61 | 'db_is_resource' => 'is_resource', |
| 61 | 62 | ); |
| 63 | + } |
|
| 62 | 64 | |
| 63 | - if (!empty($db_options['persist'])) |
|
| 64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | - else |
|
| 66 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | + if (!empty($db_options['persist'])) { |
|
| 66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | + } else { |
|
| 68 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
| 71 | 74 | if (!empty($db_options['non_fatal'])) |
| 72 | 75 | { |
| 73 | 76 | return null; |
| 74 | - } |
|
| 75 | - else |
|
| 77 | + } else |
|
| 76 | 78 | { |
| 77 | 79 | display_db_error(); |
| 78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
| 123 | 125 | |
| 124 | 126 | list ($values, $connection) = $db_callback; |
| 125 | 127 | |
| 126 | - if ($matches[1] === 'db_prefix') |
|
| 127 | - return $db_prefix; |
|
| 128 | + if ($matches[1] === 'db_prefix') { |
|
| 129 | + return $db_prefix; |
|
| 130 | + } |
|
| 128 | 131 | |
| 129 | - if ($matches[1] === 'query_see_board') |
|
| 130 | - return $user_info['query_see_board']; |
|
| 132 | + if ($matches[1] === 'query_see_board') { |
|
| 133 | + return $user_info['query_see_board']; |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 133 | - return $user_info['query_wanna_see_board']; |
|
| 136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 137 | + return $user_info['query_wanna_see_board']; |
|
| 138 | + } |
|
| 134 | 139 | |
| 135 | - if ($matches[1] === 'empty') |
|
| 136 | - return '\'\''; |
|
| 140 | + if ($matches[1] === 'empty') { |
|
| 141 | + return '\'\''; |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | - if (!isset($matches[2])) |
|
| 139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 144 | + if (!isset($matches[2])) { |
|
| 145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | - if ($matches[1] === 'literal') |
|
| 142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 148 | + if ($matches[1] === 'literal') { |
|
| 149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 150 | + } |
|
| 143 | 151 | |
| 144 | - if (!isset($values[$matches[2]])) |
|
| 145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 152 | + if (!isset($values[$matches[2]])) { |
|
| 153 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | 156 | $replacement = $values[$matches[2]]; |
| 148 | 157 | |
| 149 | 158 | switch ($matches[1]) |
| 150 | 159 | { |
| 151 | 160 | case 'int': |
| 152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 163 | + } |
|
| 154 | 164 | return (string) (int) $replacement; |
| 155 | 165 | break; |
| 156 | 166 | |
@@ -162,65 +172,73 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'time': |
| 206 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 207 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 222 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 223 | + } else { |
|
| 224 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + } |
|
| 210 | 226 | break; |
| 211 | 227 | |
| 212 | 228 | case 'datetime': |
| 213 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 214 | - return 'to_timestamp('. |
|
| 229 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 230 | + return 'to_timestamp('. |
|
| 215 | 231 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 216 | 232 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 217 | - else |
|
| 218 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + } else { |
|
| 234 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 235 | + } |
|
| 219 | 236 | break; |
| 220 | 237 | |
| 221 | 238 | case 'float': |
| 222 | - if (!is_numeric($replacement)) |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 239 | + if (!is_numeric($replacement)) { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + } |
|
| 224 | 242 | return (string) (float) $replacement; |
| 225 | 243 | break; |
| 226 | 244 | |
@@ -233,31 +251,36 @@ discard block |
||
| 233 | 251 | break; |
| 234 | 252 | |
| 235 | 253 | case 'inet': |
| 236 | - if ($replacement == 'null' || $replacement == '') |
|
| 237 | - return 'null'; |
|
| 238 | - if (inet_pton($replacement) === false) |
|
| 239 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 254 | + if ($replacement == 'null' || $replacement == '') { |
|
| 255 | + return 'null'; |
|
| 256 | + } |
|
| 257 | + if (inet_pton($replacement) === false) { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 259 | + } |
|
| 240 | 260 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 241 | 261 | |
| 242 | 262 | case 'array_inet': |
| 243 | 263 | if (is_array($replacement)) |
| 244 | 264 | { |
| 245 | - if (empty($replacement)) |
|
| 246 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 265 | + if (empty($replacement)) { |
|
| 266 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 267 | + } |
|
| 247 | 268 | |
| 248 | 269 | foreach ($replacement as $key => $value) |
| 249 | 270 | { |
| 250 | - if ($replacement == 'null' || $replacement == '') |
|
| 251 | - $replacement[$key] = 'null'; |
|
| 252 | - if (!isValidIP($value)) |
|
| 253 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + if ($replacement == 'null' || $replacement == '') { |
|
| 272 | + $replacement[$key] = 'null'; |
|
| 273 | + } |
|
| 274 | + if (!isValidIP($value)) { |
|
| 275 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 276 | + } |
|
| 254 | 277 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 255 | 278 | } |
| 256 | 279 | |
| 257 | 280 | return implode(', ', $replacement); |
| 281 | + } else { |
|
| 282 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 258 | 283 | } |
| 259 | - else |
|
| 260 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | 284 | break; |
| 262 | 285 | |
| 263 | 286 | default: |
@@ -344,14 +367,16 @@ discard block |
||
| 344 | 367 | ), |
| 345 | 368 | ); |
| 346 | 369 | |
| 347 | - if (isset($replacements[$identifier])) |
|
| 348 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 370 | + if (isset($replacements[$identifier])) { |
|
| 371 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 372 | + } |
|
| 349 | 373 | |
| 350 | 374 | // Limits need to be a little different. |
| 351 | 375 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 352 | 376 | |
| 353 | - if (trim($db_string) == '') |
|
| 354 | - return false; |
|
| 377 | + if (trim($db_string) == '') { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 355 | 380 | |
| 356 | 381 | // Comments that are allowed in a query are preg_removed. |
| 357 | 382 | static $allowed_comments_from = array( |
@@ -371,8 +396,9 @@ discard block |
||
| 371 | 396 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 372 | 397 | $db_replace_result = 0; |
| 373 | 398 | |
| 374 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 375 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 399 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 400 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 401 | + } |
|
| 376 | 402 | |
| 377 | 403 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 378 | 404 | { |
@@ -393,8 +419,9 @@ discard block |
||
| 393 | 419 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 394 | 420 | |
| 395 | 421 | // Initialize $db_cache if not already initialized. |
| 396 | - if (!isset($db_cache)) |
|
| 397 | - $db_cache = array(); |
|
| 422 | + if (!isset($db_cache)) { |
|
| 423 | + $db_cache = array(); |
|
| 424 | + } |
|
| 398 | 425 | |
| 399 | 426 | if (!empty($_SESSION['debug_redirect'])) |
| 400 | 427 | { |
@@ -420,17 +447,18 @@ discard block |
||
| 420 | 447 | while (true) |
| 421 | 448 | { |
| 422 | 449 | $pos = strpos($db_string, '\'', $pos + 1); |
| 423 | - if ($pos === false) |
|
| 424 | - break; |
|
| 450 | + if ($pos === false) { |
|
| 451 | + break; |
|
| 452 | + } |
|
| 425 | 453 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 426 | 454 | |
| 427 | 455 | while (true) |
| 428 | 456 | { |
| 429 | 457 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 430 | 458 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 431 | - if ($pos1 === false) |
|
| 432 | - break; |
|
| 433 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 459 | + if ($pos1 === false) { |
|
| 460 | + break; |
|
| 461 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 434 | 462 | { |
| 435 | 463 | $pos = $pos1; |
| 436 | 464 | break; |
@@ -446,26 +474,31 @@ discard block |
||
| 446 | 474 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 447 | 475 | |
| 448 | 476 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 449 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 450 | - $fail = true; |
|
| 477 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 478 | + $fail = true; |
|
| 479 | + } |
|
| 451 | 480 | // Trying to change passwords, slow us down, or something? |
| 452 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 453 | - $fail = true; |
|
| 454 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 455 | - $fail = true; |
|
| 481 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 482 | + $fail = true; |
|
| 483 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 484 | + $fail = true; |
|
| 485 | + } |
|
| 456 | 486 | |
| 457 | - if (!empty($fail) && function_exists('log_error')) |
|
| 458 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 487 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 488 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 489 | + } |
|
| 459 | 490 | } |
| 460 | 491 | |
| 461 | 492 | $db_last_result = @pg_query($connection, $db_string); |
| 462 | 493 | |
| 463 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 464 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 494 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 495 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 496 | + } |
|
| 465 | 497 | |
| 466 | 498 | // Debugging. |
| 467 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 468 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 499 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 500 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 501 | + } |
|
| 469 | 502 | |
| 470 | 503 | return $db_last_result; |
| 471 | 504 | } |
@@ -478,10 +511,11 @@ discard block |
||
| 478 | 511 | { |
| 479 | 512 | global $db_last_result, $db_replace_result; |
| 480 | 513 | |
| 481 | - if ($db_replace_result) |
|
| 482 | - return $db_replace_result; |
|
| 483 | - elseif ($result === null && !$db_last_result) |
|
| 484 | - return 0; |
|
| 514 | + if ($db_replace_result) { |
|
| 515 | + return $db_replace_result; |
|
| 516 | + } elseif ($result === null && !$db_last_result) { |
|
| 517 | + return 0; |
|
| 518 | + } |
|
| 485 | 519 | |
| 486 | 520 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 487 | 521 | } |
@@ -505,8 +539,9 @@ discard block |
||
| 505 | 539 | array( |
| 506 | 540 | ) |
| 507 | 541 | ); |
| 508 | - if (!$request) |
|
| 509 | - return false; |
|
| 542 | + if (!$request) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 510 | 545 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 511 | 546 | $smcFunc['db_free_result']($request); |
| 512 | 547 | |
@@ -527,12 +562,13 @@ discard block |
||
| 527 | 562 | // Decide which connection to use |
| 528 | 563 | $connection = $connection === null ? $db_connection : $connection; |
| 529 | 564 | |
| 530 | - if ($type == 'begin') |
|
| 531 | - return @pg_query($connection, 'BEGIN'); |
|
| 532 | - elseif ($type == 'rollback') |
|
| 533 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 534 | - elseif ($type == 'commit') |
|
| 535 | - return @pg_query($connection, 'COMMIT'); |
|
| 565 | + if ($type == 'begin') { |
|
| 566 | + return @pg_query($connection, 'BEGIN'); |
|
| 567 | + } elseif ($type == 'rollback') { |
|
| 568 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 569 | + } elseif ($type == 'commit') { |
|
| 570 | + return @pg_query($connection, 'COMMIT'); |
|
| 571 | + } |
|
| 536 | 572 | |
| 537 | 573 | return false; |
| 538 | 574 | } |
@@ -560,19 +596,22 @@ discard block |
||
| 560 | 596 | $query_error = @pg_last_error($connection); |
| 561 | 597 | |
| 562 | 598 | // Log the error. |
| 563 | - if (function_exists('log_error')) |
|
| 564 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 599 | + if (function_exists('log_error')) { |
|
| 600 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 601 | + } |
|
| 565 | 602 | |
| 566 | 603 | // Nothing's defined yet... just die with it. |
| 567 | - if (empty($context) || empty($txt)) |
|
| 568 | - die($query_error); |
|
| 604 | + if (empty($context) || empty($txt)) { |
|
| 605 | + die($query_error); |
|
| 606 | + } |
|
| 569 | 607 | |
| 570 | 608 | // Show an error message, if possible. |
| 571 | 609 | $context['error_title'] = $txt['database_error']; |
| 572 | - if (allowedTo('admin_forum')) |
|
| 573 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 574 | - else |
|
| 575 | - $context['error_message'] = $txt['try_again']; |
|
| 610 | + if (allowedTo('admin_forum')) { |
|
| 611 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 612 | + } else { |
|
| 613 | + $context['error_message'] = $txt['try_again']; |
|
| 614 | + } |
|
| 576 | 615 | |
| 577 | 616 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 578 | 617 | { |
@@ -594,12 +633,14 @@ discard block |
||
| 594 | 633 | { |
| 595 | 634 | global $db_row_count; |
| 596 | 635 | |
| 597 | - if ($counter !== false) |
|
| 598 | - return pg_fetch_row($request, $counter); |
|
| 636 | + if ($counter !== false) { |
|
| 637 | + return pg_fetch_row($request, $counter); |
|
| 638 | + } |
|
| 599 | 639 | |
| 600 | 640 | // Reset the row counter... |
| 601 | - if (!isset($db_row_count[(int) $request])) |
|
| 602 | - $db_row_count[(int) $request] = 0; |
|
| 641 | + if (!isset($db_row_count[(int) $request])) { |
|
| 642 | + $db_row_count[(int) $request] = 0; |
|
| 643 | + } |
|
| 603 | 644 | |
| 604 | 645 | // Return the right row. |
| 605 | 646 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -616,12 +657,14 @@ discard block |
||
| 616 | 657 | { |
| 617 | 658 | global $db_row_count; |
| 618 | 659 | |
| 619 | - if ($counter !== false) |
|
| 620 | - return pg_fetch_assoc($request, $counter); |
|
| 660 | + if ($counter !== false) { |
|
| 661 | + return pg_fetch_assoc($request, $counter); |
|
| 662 | + } |
|
| 621 | 663 | |
| 622 | 664 | // Reset the row counter... |
| 623 | - if (!isset($db_row_count[(int) $request])) |
|
| 624 | - $db_row_count[(int) $request] = 0; |
|
| 665 | + if (!isset($db_row_count[(int) $request])) { |
|
| 666 | + $db_row_count[(int) $request] = 0; |
|
| 667 | + } |
|
| 625 | 668 | |
| 626 | 669 | // Return the right row. |
| 627 | 670 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -674,11 +717,13 @@ discard block |
||
| 674 | 717 | |
| 675 | 718 | $replace = ''; |
| 676 | 719 | |
| 677 | - if (empty($data)) |
|
| 678 | - return; |
|
| 720 | + if (empty($data)) { |
|
| 721 | + return; |
|
| 722 | + } |
|
| 679 | 723 | |
| 680 | - if (!is_array($data[array_rand($data)])) |
|
| 681 | - $data = array($data); |
|
| 724 | + if (!is_array($data[array_rand($data)])) { |
|
| 725 | + $data = array($data); |
|
| 726 | + } |
|
| 682 | 727 | |
| 683 | 728 | // Replace the prefix holder with the actual prefix. |
| 684 | 729 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -697,11 +742,13 @@ discard block |
||
| 697 | 742 | //pg 9.5 got replace support |
| 698 | 743 | $pg_version = $smcFunc['db_get_version'](); |
| 699 | 744 | // if we got a Beta Version |
| 700 | - if (stripos($pg_version, 'beta') !== false) |
|
| 701 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 745 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 746 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 747 | + } |
|
| 702 | 748 | // or RC |
| 703 | - if (stripos($pg_version, 'rc') !== false) |
|
| 704 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 749 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 750 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 751 | + } |
|
| 705 | 752 | |
| 706 | 753 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 707 | 754 | } |
@@ -720,8 +767,7 @@ discard block |
||
| 720 | 767 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 721 | 768 | $key_str .= $columnName; |
| 722 | 769 | $count_pk++; |
| 723 | - } |
|
| 724 | - else //normal field |
|
| 770 | + } else //normal field |
|
| 725 | 771 | { |
| 726 | 772 | $col_str .= ($count > 0 ? ',' : ''); |
| 727 | 773 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -729,20 +775,21 @@ discard block |
||
| 729 | 775 | } |
| 730 | 776 | } |
| 731 | 777 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
| 732 | - } |
|
| 733 | - else |
|
| 778 | + } else |
|
| 734 | 779 | { |
| 735 | 780 | foreach ($columns as $columnName => $type) |
| 736 | 781 | { |
| 737 | 782 | // Are we restricting the length? |
| 738 | - if (strpos($type, 'string-') !== false) |
|
| 739 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 740 | - else |
|
| 741 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 783 | + if (strpos($type, 'string-') !== false) { |
|
| 784 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 785 | + } else { |
|
| 786 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 787 | + } |
|
| 742 | 788 | |
| 743 | 789 | // A key? That's what we were looking for. |
| 744 | - if (in_array($columnName, $keys)) |
|
| 745 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 790 | + if (in_array($columnName, $keys)) { |
|
| 791 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 792 | + } |
|
| 746 | 793 | $count++; |
| 747 | 794 | } |
| 748 | 795 | |
@@ -778,10 +825,11 @@ discard block |
||
| 778 | 825 | foreach ($columns as $columnName => $type) |
| 779 | 826 | { |
| 780 | 827 | // Are we restricting the length? |
| 781 | - if (strpos($type, 'string-') !== false) |
|
| 782 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 783 | - else |
|
| 784 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 828 | + if (strpos($type, 'string-') !== false) { |
|
| 829 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 830 | + } else { |
|
| 831 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 832 | + } |
|
| 785 | 833 | } |
| 786 | 834 | $insertData = substr($insertData, 0, -2) . ')'; |
| 787 | 835 | |
@@ -790,8 +838,9 @@ discard block |
||
| 790 | 838 | |
| 791 | 839 | // Here's where the variables are injected to the query. |
| 792 | 840 | $insertRows = array(); |
| 793 | - foreach ($data as $dataRow) |
|
| 794 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 841 | + foreach ($data as $dataRow) { |
|
| 842 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 843 | + } |
|
| 795 | 844 | |
| 796 | 845 | // Do the insert. |
| 797 | 846 | $request = $smcFunc['db_query']('', ' |
@@ -808,19 +857,21 @@ discard block |
||
| 808 | 857 | |
| 809 | 858 | if ($with_returning && $request !== false) |
| 810 | 859 | { |
| 811 | - if ($returnmode === 2) |
|
| 812 | - $return_var = array(); |
|
| 860 | + if ($returnmode === 2) { |
|
| 861 | + $return_var = array(); |
|
| 862 | + } |
|
| 813 | 863 | |
| 814 | 864 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 815 | 865 | { |
| 816 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 866 | + if (is_numeric($row[0])) { |
|
| 867 | + // try to emulate mysql limitation |
|
| 817 | 868 | { |
| 818 | 869 | if ($returnmode === 1) |
| 819 | 870 | $return_var = $row[0]; |
| 820 | - elseif ($returnmode === 2) |
|
| 821 | - $return_var[] = $row[0]; |
|
| 822 | - } |
|
| 823 | - else |
|
| 871 | + } elseif ($returnmode === 2) { |
|
| 872 | + $return_var[] = $row[0]; |
|
| 873 | + } |
|
| 874 | + } else |
|
| 824 | 875 | { |
| 825 | 876 | $with_returning = false; |
| 826 | 877 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -829,9 +880,10 @@ discard block |
||
| 829 | 880 | } |
| 830 | 881 | } |
| 831 | 882 | |
| 832 | - if ($with_returning && !empty($return_var)) |
|
| 833 | - return $return_var; |
|
| 834 | -} |
|
| 883 | + if ($with_returning && !empty($return_var)) { |
|
| 884 | + return $return_var; |
|
| 885 | + } |
|
| 886 | + } |
|
| 835 | 887 | |
| 836 | 888 | /** |
| 837 | 889 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -868,8 +920,9 @@ discard block |
||
| 868 | 920 | */ |
| 869 | 921 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 870 | 922 | { |
| 871 | - if (empty($log_message)) |
|
| 872 | - $log_message = $error_message; |
|
| 923 | + if (empty($log_message)) { |
|
| 924 | + $log_message = $error_message; |
|
| 925 | + } |
|
| 873 | 926 | |
| 874 | 927 | foreach (debug_backtrace() as $step) |
| 875 | 928 | { |
@@ -888,12 +941,14 @@ discard block |
||
| 888 | 941 | } |
| 889 | 942 | |
| 890 | 943 | // A special case - we want the file and line numbers for debugging. |
| 891 | - if ($error_type == 'return') |
|
| 892 | - return array($file, $line); |
|
| 944 | + if ($error_type == 'return') { |
|
| 945 | + return array($file, $line); |
|
| 946 | + } |
|
| 893 | 947 | |
| 894 | 948 | // Is always a critical error. |
| 895 | - if (function_exists('log_error')) |
|
| 896 | - log_error($log_message, 'critical', $file, $line); |
|
| 949 | + if (function_exists('log_error')) { |
|
| 950 | + log_error($log_message, 'critical', $file, $line); |
|
| 951 | + } |
|
| 897 | 952 | |
| 898 | 953 | if (function_exists('fatal_error')) |
| 899 | 954 | { |
@@ -901,12 +956,12 @@ discard block |
||
| 901 | 956 | |
| 902 | 957 | // Cannot continue... |
| 903 | 958 | exit; |
| 959 | + } elseif ($error_type) { |
|
| 960 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 961 | + } else { |
|
| 962 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 963 | + } |
|
| 904 | 964 | } |
| 905 | - elseif ($error_type) |
|
| 906 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 907 | - else |
|
| 908 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 909 | -} |
|
| 910 | 965 | |
| 911 | 966 | /** |
| 912 | 967 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -923,10 +978,11 @@ discard block |
||
| 923 | 978 | '\\' => '\\\\', |
| 924 | 979 | ); |
| 925 | 980 | |
| 926 | - if ($translate_human_wildcards) |
|
| 927 | - $replacements += array( |
|
| 981 | + if ($translate_human_wildcards) { |
|
| 982 | + $replacements += array( |
|
| 928 | 983 | '*' => '%', |
| 929 | 984 | ); |
| 985 | + } |
|
| 930 | 986 | |
| 931 | 987 | return strtr($string, $replacements); |
| 932 | 988 | } |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | case 'datetime': |
| 257 | 257 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
| 258 | - return 'str_to_date('. |
|
| 259 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
| 258 | + return 'str_to_date(' . |
|
| 259 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
| 260 | 260 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 261 | 261 | else |
| 262 | 262 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | $connection |
| 824 | 824 | ); |
| 825 | 825 | |
| 826 | - if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 826 | + if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
|
| 827 | 827 | { |
| 828 | 828 | if ($returnmode == 1) |
| 829 | 829 | $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | $return_var = array(); |
| 833 | 833 | $count = count($insertRows); |
| 834 | 834 | $start = smf_db_insert_id($table, $keys[0]); |
| 835 | - for ($i = 0; $i < $count; $i++ ) |
|
| 835 | + for ($i = 0; $i < $count; $i++) |
|
| 836 | 836 | $return_var[] = $start + $i; |
| 837 | 837 | } |
| 838 | 838 | return $return_var; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc, $mysql_set_mode; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -58,9 +59,11 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'smf_is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['persist'])) |
|
| 63 | - $db_server = 'p:' . $db_server; |
|
| 64 | + if (!empty($db_options['persist'])) { |
|
| 65 | + $db_server = 'p:' . $db_server; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $connection = mysqli_init(); |
| 66 | 69 | |
@@ -69,31 +72,35 @@ discard block |
||
| 69 | 72 | $success = false; |
| 70 | 73 | |
| 71 | 74 | if ($connection) { |
| 72 | - if (!empty($db_options['port'])) |
|
| 73 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 74 | - else |
|
| 75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 75 | + if (!empty($db_options['port'])) { |
|
| 76 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 77 | + } else { |
|
| 78 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 79 | + } |
|
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 79 | 83 | if ($success === false) |
| 80 | 84 | { |
| 81 | - if (!empty($db_options['non_fatal'])) |
|
| 82 | - return null; |
|
| 83 | - else |
|
| 84 | - display_db_error(); |
|
| 85 | + if (!empty($db_options['non_fatal'])) { |
|
| 86 | + return null; |
|
| 87 | + } else { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 85 | 90 | } |
| 86 | 91 | |
| 87 | 92 | // Select the database, unless told not to |
| 88 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 89 | - display_db_error(); |
|
| 93 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 94 | + display_db_error(); |
|
| 95 | + } |
|
| 90 | 96 | |
| 91 | 97 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 92 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 93 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 98 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 99 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 94 | 100 | array(), |
| 95 | 101 | false |
| 96 | 102 | ); |
| 103 | + } |
|
| 97 | 104 | |
| 98 | 105 | return $connection; |
| 99 | 106 | } |
@@ -164,37 +171,46 @@ discard block |
||
| 164 | 171 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 165 | 172 | |
| 166 | 173 | list ($values, $connection) = $db_callback; |
| 167 | - if (!is_object($connection)) |
|
| 168 | - display_db_error(); |
|
| 174 | + if (!is_object($connection)) { |
|
| 175 | + display_db_error(); |
|
| 176 | + } |
|
| 169 | 177 | |
| 170 | - if ($matches[1] === 'db_prefix') |
|
| 171 | - return $db_prefix; |
|
| 178 | + if ($matches[1] === 'db_prefix') { |
|
| 179 | + return $db_prefix; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | - if ($matches[1] === 'query_see_board') |
|
| 174 | - return $user_info['query_see_board']; |
|
| 182 | + if ($matches[1] === 'query_see_board') { |
|
| 183 | + return $user_info['query_see_board']; |
|
| 184 | + } |
|
| 175 | 185 | |
| 176 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 177 | - return $user_info['query_wanna_see_board']; |
|
| 186 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 187 | + return $user_info['query_wanna_see_board']; |
|
| 188 | + } |
|
| 178 | 189 | |
| 179 | - if ($matches[1] === 'empty') |
|
| 180 | - return '\'\''; |
|
| 190 | + if ($matches[1] === 'empty') { |
|
| 191 | + return '\'\''; |
|
| 192 | + } |
|
| 181 | 193 | |
| 182 | - if (!isset($matches[2])) |
|
| 183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | + if (!isset($matches[2])) { |
|
| 195 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | + } |
|
| 184 | 197 | |
| 185 | - if ($matches[1] === 'literal') |
|
| 186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 198 | + if ($matches[1] === 'literal') { |
|
| 199 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 200 | + } |
|
| 187 | 201 | |
| 188 | - if (!isset($values[$matches[2]])) |
|
| 189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 202 | + if (!isset($values[$matches[2]])) { |
|
| 203 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 204 | + } |
|
| 190 | 205 | |
| 191 | 206 | $replacement = $values[$matches[2]]; |
| 192 | 207 | |
| 193 | 208 | switch ($matches[1]) |
| 194 | 209 | { |
| 195 | 210 | case 'int': |
| 196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 211 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 212 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + } |
|
| 198 | 214 | return (string) (int) $replacement; |
| 199 | 215 | break; |
| 200 | 216 | |
@@ -206,65 +222,73 @@ discard block |
||
| 206 | 222 | case 'array_int': |
| 207 | 223 | if (is_array($replacement)) |
| 208 | 224 | { |
| 209 | - if (empty($replacement)) |
|
| 210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + if (empty($replacement)) { |
|
| 226 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | + } |
|
| 211 | 228 | |
| 212 | 229 | foreach ($replacement as $key => $value) |
| 213 | 230 | { |
| 214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 232 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + } |
|
| 216 | 234 | |
| 217 | 235 | $replacement[$key] = (string) (int) $value; |
| 218 | 236 | } |
| 219 | 237 | |
| 220 | 238 | return implode(', ', $replacement); |
| 239 | + } else { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | 241 | } |
| 222 | - else |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 224 | 242 | |
| 225 | 243 | break; |
| 226 | 244 | |
| 227 | 245 | case 'array_string': |
| 228 | 246 | if (is_array($replacement)) |
| 229 | 247 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + if (empty($replacement)) { |
|
| 249 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + } |
|
| 232 | 251 | |
| 233 | - foreach ($replacement as $key => $value) |
|
| 234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 252 | + foreach ($replacement as $key => $value) { |
|
| 253 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 254 | + } |
|
| 235 | 255 | |
| 236 | 256 | return implode(', ', $replacement); |
| 257 | + } else { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | 259 | } |
| 238 | - else |
|
| 239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | 260 | break; |
| 241 | 261 | |
| 242 | 262 | case 'date': |
| 243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 245 | - else |
|
| 246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 264 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 265 | + } else { |
|
| 266 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 267 | + } |
|
| 247 | 268 | break; |
| 248 | 269 | |
| 249 | 270 | case 'time': |
| 250 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 251 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 252 | - else |
|
| 253 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 272 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 273 | + } else { |
|
| 274 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 275 | + } |
|
| 254 | 276 | break; |
| 255 | 277 | |
| 256 | 278 | case 'datetime': |
| 257 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 258 | - return 'str_to_date('. |
|
| 279 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 280 | + return 'str_to_date('. |
|
| 259 | 281 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 260 | 282 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 261 | - else |
|
| 262 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 283 | + } else { |
|
| 284 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 285 | + } |
|
| 263 | 286 | break; |
| 264 | 287 | |
| 265 | 288 | case 'float': |
| 266 | - if (!is_numeric($replacement)) |
|
| 267 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 289 | + if (!is_numeric($replacement)) { |
|
| 290 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 291 | + } |
|
| 268 | 292 | return (string) (float) $replacement; |
| 269 | 293 | break; |
| 270 | 294 | |
@@ -278,32 +302,37 @@ discard block |
||
| 278 | 302 | break; |
| 279 | 303 | |
| 280 | 304 | case 'inet': |
| 281 | - if ($replacement == 'null' || $replacement == '') |
|
| 282 | - return 'null'; |
|
| 283 | - if (!isValidIP($replacement)) |
|
| 284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 305 | + if ($replacement == 'null' || $replacement == '') { |
|
| 306 | + return 'null'; |
|
| 307 | + } |
|
| 308 | + if (!isValidIP($replacement)) { |
|
| 309 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 310 | + } |
|
| 285 | 311 | //we don't use the native support of mysql > 5.6.2 |
| 286 | 312 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 287 | 313 | |
| 288 | 314 | case 'array_inet': |
| 289 | 315 | if (is_array($replacement)) |
| 290 | 316 | { |
| 291 | - if (empty($replacement)) |
|
| 292 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 317 | + if (empty($replacement)) { |
|
| 318 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 319 | + } |
|
| 293 | 320 | |
| 294 | 321 | foreach ($replacement as $key => $value) |
| 295 | 322 | { |
| 296 | - if ($replacement == 'null' || $replacement == '') |
|
| 297 | - $replacement[$key] = 'null'; |
|
| 298 | - if (!isValidIP($value)) |
|
| 299 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 323 | + if ($replacement == 'null' || $replacement == '') { |
|
| 324 | + $replacement[$key] = 'null'; |
|
| 325 | + } |
|
| 326 | + if (!isValidIP($value)) { |
|
| 327 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 328 | + } |
|
| 300 | 329 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 301 | 330 | } |
| 302 | 331 | |
| 303 | 332 | return implode(', ', $replacement); |
| 333 | + } else { |
|
| 334 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 304 | 335 | } |
| 305 | - else |
|
| 306 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 307 | 336 | break; |
| 308 | 337 | |
| 309 | 338 | default: |
@@ -379,22 +408,25 @@ discard block |
||
| 379 | 408 | // Are we in SSI mode? If so try that username and password first |
| 380 | 409 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 381 | 410 | { |
| 382 | - if (empty($db_persist)) |
|
| 383 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 384 | - else |
|
| 385 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 411 | + if (empty($db_persist)) { |
|
| 412 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 413 | + } else { |
|
| 414 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 415 | + } |
|
| 386 | 416 | } |
| 387 | 417 | // Fall back to the regular username and password if need be |
| 388 | 418 | if (!$db_connection) |
| 389 | 419 | { |
| 390 | - if (empty($db_persist)) |
|
| 391 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 392 | - else |
|
| 393 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 420 | + if (empty($db_persist)) { |
|
| 421 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 422 | + } else { |
|
| 423 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 424 | + } |
|
| 394 | 425 | } |
| 395 | 426 | |
| 396 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 397 | - $db_connection = false; |
|
| 427 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 428 | + $db_connection = false; |
|
| 429 | + } |
|
| 398 | 430 | |
| 399 | 431 | $connection = $db_connection; |
| 400 | 432 | } |
@@ -402,18 +434,20 @@ discard block |
||
| 402 | 434 | // One more query.... |
| 403 | 435 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 404 | 436 | |
| 405 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 406 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 437 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 438 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 439 | + } |
|
| 407 | 440 | |
| 408 | 441 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 409 | 442 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 410 | 443 | { |
| 411 | 444 | // Add before LIMIT |
| 412 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 413 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 414 | - else |
|
| 415 | - // Append it. |
|
| 445 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 446 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 447 | + } else { |
|
| 448 | + // Append it. |
|
| 416 | 449 | $db_string .= "\n\t\t\tORDER BY null"; |
| 450 | + } |
|
| 417 | 451 | } |
| 418 | 452 | |
| 419 | 453 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -435,8 +469,9 @@ discard block |
||
| 435 | 469 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 436 | 470 | |
| 437 | 471 | // Initialize $db_cache if not already initialized. |
| 438 | - if (!isset($db_cache)) |
|
| 439 | - $db_cache = array(); |
|
| 472 | + if (!isset($db_cache)) { |
|
| 473 | + $db_cache = array(); |
|
| 474 | + } |
|
| 440 | 475 | |
| 441 | 476 | if (!empty($_SESSION['debug_redirect'])) |
| 442 | 477 | { |
@@ -462,17 +497,18 @@ discard block |
||
| 462 | 497 | while (true) |
| 463 | 498 | { |
| 464 | 499 | $pos = strpos($db_string, '\'', $pos + 1); |
| 465 | - if ($pos === false) |
|
| 466 | - break; |
|
| 500 | + if ($pos === false) { |
|
| 501 | + break; |
|
| 502 | + } |
|
| 467 | 503 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 468 | 504 | |
| 469 | 505 | while (true) |
| 470 | 506 | { |
| 471 | 507 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 472 | 508 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 473 | - if ($pos1 === false) |
|
| 474 | - break; |
|
| 475 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 509 | + if ($pos1 === false) { |
|
| 510 | + break; |
|
| 511 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 476 | 512 | { |
| 477 | 513 | $pos = $pos1; |
| 478 | 514 | break; |
@@ -488,29 +524,35 @@ discard block |
||
| 488 | 524 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 489 | 525 | |
| 490 | 526 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 491 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 492 | - $fail = true; |
|
| 527 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 528 | + $fail = true; |
|
| 529 | + } |
|
| 493 | 530 | // Trying to change passwords, slow us down, or something? |
| 494 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 495 | - $fail = true; |
|
| 496 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 497 | - $fail = true; |
|
| 531 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 532 | + $fail = true; |
|
| 533 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 534 | + $fail = true; |
|
| 535 | + } |
|
| 498 | 536 | |
| 499 | - if (!empty($fail) && function_exists('log_error')) |
|
| 500 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 537 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 538 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 539 | + } |
|
| 501 | 540 | } |
| 502 | 541 | |
| 503 | - if (empty($db_unbuffered)) |
|
| 504 | - $ret = @mysqli_query($connection, $db_string); |
|
| 505 | - else |
|
| 506 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 542 | + if (empty($db_unbuffered)) { |
|
| 543 | + $ret = @mysqli_query($connection, $db_string); |
|
| 544 | + } else { |
|
| 545 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 546 | + } |
|
| 507 | 547 | |
| 508 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 509 | - $ret = smf_db_error($db_string, $connection); |
|
| 548 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 549 | + $ret = smf_db_error($db_string, $connection); |
|
| 550 | + } |
|
| 510 | 551 | |
| 511 | 552 | // Debugging. |
| 512 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 513 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 553 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 554 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 555 | + } |
|
| 514 | 556 | |
| 515 | 557 | return $ret; |
| 516 | 558 | } |
@@ -557,12 +599,13 @@ discard block |
||
| 557 | 599 | // Decide which connection to use |
| 558 | 600 | $connection = $connection === null ? $db_connection : $connection; |
| 559 | 601 | |
| 560 | - if ($type == 'begin') |
|
| 561 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 562 | - elseif ($type == 'rollback') |
|
| 563 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 564 | - elseif ($type == 'commit') |
|
| 565 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 602 | + if ($type == 'begin') { |
|
| 603 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 604 | + } elseif ($type == 'rollback') { |
|
| 605 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 606 | + } elseif ($type == 'commit') { |
|
| 607 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 608 | + } |
|
| 566 | 609 | |
| 567 | 610 | return false; |
| 568 | 611 | } |
@@ -602,8 +645,9 @@ discard block |
||
| 602 | 645 | // 2013: Lost connection to server during query. |
| 603 | 646 | |
| 604 | 647 | // Log the error. |
| 605 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 606 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 648 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 649 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 650 | + } |
|
| 607 | 651 | |
| 608 | 652 | // Database error auto fixing ;). |
| 609 | 653 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -612,8 +656,9 @@ discard block |
||
| 612 | 656 | $old_cache = @$modSettings['cache_enable']; |
| 613 | 657 | $modSettings['cache_enable'] = '1'; |
| 614 | 658 | |
| 615 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 616 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 659 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 660 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 661 | + } |
|
| 617 | 662 | |
| 618 | 663 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 619 | 664 | { |
@@ -629,8 +674,9 @@ discard block |
||
| 629 | 674 | foreach ($tables as $table) |
| 630 | 675 | { |
| 631 | 676 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 632 | - if (trim($table) != '') |
|
| 633 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 677 | + if (trim($table) != '') { |
|
| 678 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 679 | + } |
|
| 634 | 680 | } |
| 635 | 681 | } |
| 636 | 682 | |
@@ -639,8 +685,9 @@ discard block |
||
| 639 | 685 | // Table crashed. Let's try to fix it. |
| 640 | 686 | elseif ($query_errno == 1016) |
| 641 | 687 | { |
| 642 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 643 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 688 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 689 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 690 | + } |
|
| 644 | 691 | } |
| 645 | 692 | // Indexes crashed. Should be easy to fix! |
| 646 | 693 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -659,13 +706,15 @@ discard block |
||
| 659 | 706 | |
| 660 | 707 | // Make a note of the REPAIR... |
| 661 | 708 | cache_put_data('db_last_error', time(), 600); |
| 662 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 663 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 709 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 710 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 711 | + } |
|
| 664 | 712 | |
| 665 | 713 | // Attempt to find and repair the broken table. |
| 666 | - foreach ($fix_tables as $table) |
|
| 667 | - $smcFunc['db_query']('', " |
|
| 714 | + foreach ($fix_tables as $table) { |
|
| 715 | + $smcFunc['db_query']('', " |
|
| 668 | 716 | REPAIR TABLE $table", false, false); |
| 717 | + } |
|
| 669 | 718 | |
| 670 | 719 | // And send off an email! |
| 671 | 720 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -674,11 +723,12 @@ discard block |
||
| 674 | 723 | |
| 675 | 724 | // Try the query again...? |
| 676 | 725 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 677 | - if ($ret !== false) |
|
| 678 | - return $ret; |
|
| 726 | + if ($ret !== false) { |
|
| 727 | + return $ret; |
|
| 728 | + } |
|
| 729 | + } else { |
|
| 730 | + $modSettings['cache_enable'] = $old_cache; |
|
| 679 | 731 | } |
| 680 | - else |
|
| 681 | - $modSettings['cache_enable'] = $old_cache; |
|
| 682 | 732 | |
| 683 | 733 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 684 | 734 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -688,22 +738,25 @@ discard block |
||
| 688 | 738 | // Are we in SSI mode? If so try that username and password first |
| 689 | 739 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 690 | 740 | { |
| 691 | - if (empty($db_persist)) |
|
| 692 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 693 | - else |
|
| 694 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 741 | + if (empty($db_persist)) { |
|
| 742 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 743 | + } else { |
|
| 744 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 745 | + } |
|
| 695 | 746 | } |
| 696 | 747 | // Fall back to the regular username and password if need be |
| 697 | 748 | if (!$db_connection) |
| 698 | 749 | { |
| 699 | - if (empty($db_persist)) |
|
| 700 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 701 | - else |
|
| 702 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 750 | + if (empty($db_persist)) { |
|
| 751 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 752 | + } else { |
|
| 753 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 754 | + } |
|
| 703 | 755 | } |
| 704 | 756 | |
| 705 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 706 | - $db_connection = false; |
|
| 757 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 758 | + $db_connection = false; |
|
| 759 | + } |
|
| 707 | 760 | } |
| 708 | 761 | |
| 709 | 762 | if ($db_connection) |
@@ -714,24 +767,27 @@ discard block |
||
| 714 | 767 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 715 | 768 | |
| 716 | 769 | $new_errno = mysqli_errno($db_connection); |
| 717 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 718 | - break; |
|
| 770 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 771 | + break; |
|
| 772 | + } |
|
| 719 | 773 | } |
| 720 | 774 | |
| 721 | 775 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 722 | - if ($ret !== false) |
|
| 723 | - return $ret; |
|
| 776 | + if ($ret !== false) { |
|
| 777 | + return $ret; |
|
| 778 | + } |
|
| 724 | 779 | } |
| 725 | 780 | } |
| 726 | 781 | // Are they out of space, perhaps? |
| 727 | 782 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 728 | 783 | { |
| 729 | - if (!isset($txt)) |
|
| 730 | - $query_error .= ' - check database storage space.'; |
|
| 731 | - else |
|
| 784 | + if (!isset($txt)) { |
|
| 785 | + $query_error .= ' - check database storage space.'; |
|
| 786 | + } else |
|
| 732 | 787 | { |
| 733 | - if (!isset($txt['mysql_error_space'])) |
|
| 734 | - loadLanguage('Errors'); |
|
| 788 | + if (!isset($txt['mysql_error_space'])) { |
|
| 789 | + loadLanguage('Errors'); |
|
| 790 | + } |
|
| 735 | 791 | |
| 736 | 792 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 737 | 793 | } |
@@ -739,15 +795,17 @@ discard block |
||
| 739 | 795 | } |
| 740 | 796 | |
| 741 | 797 | // Nothing's defined yet... just die with it. |
| 742 | - if (empty($context) || empty($txt)) |
|
| 743 | - die($query_error); |
|
| 798 | + if (empty($context) || empty($txt)) { |
|
| 799 | + die($query_error); |
|
| 800 | + } |
|
| 744 | 801 | |
| 745 | 802 | // Show an error message, if possible. |
| 746 | 803 | $context['error_title'] = $txt['database_error']; |
| 747 | - if (allowedTo('admin_forum')) |
|
| 748 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 749 | - else |
|
| 750 | - $context['error_message'] = $txt['try_again']; |
|
| 804 | + if (allowedTo('admin_forum')) { |
|
| 805 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 806 | + } else { |
|
| 807 | + $context['error_message'] = $txt['try_again']; |
|
| 808 | + } |
|
| 751 | 809 | |
| 752 | 810 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 753 | 811 | { |
@@ -777,25 +835,28 @@ discard block |
||
| 777 | 835 | $connection = $connection === null ? $db_connection : $connection; |
| 778 | 836 | |
| 779 | 837 | // With nothing to insert, simply return. |
| 780 | - if (empty($data)) |
|
| 781 | - return; |
|
| 838 | + if (empty($data)) { |
|
| 839 | + return; |
|
| 840 | + } |
|
| 782 | 841 | |
| 783 | 842 | // Replace the prefix holder with the actual prefix. |
| 784 | 843 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 785 | 844 | |
| 786 | 845 | // Inserting data as a single row can be done as a single array. |
| 787 | - if (!is_array($data[array_rand($data)])) |
|
| 788 | - $data = array($data); |
|
| 846 | + if (!is_array($data[array_rand($data)])) { |
|
| 847 | + $data = array($data); |
|
| 848 | + } |
|
| 789 | 849 | |
| 790 | 850 | // Create the mold for a single row insert. |
| 791 | 851 | $insertData = '('; |
| 792 | 852 | foreach ($columns as $columnName => $type) |
| 793 | 853 | { |
| 794 | 854 | // Are we restricting the length? |
| 795 | - if (strpos($type, 'string-') !== false) |
|
| 796 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 797 | - else |
|
| 798 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 855 | + if (strpos($type, 'string-') !== false) { |
|
| 856 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 857 | + } else { |
|
| 858 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 859 | + } |
|
| 799 | 860 | } |
| 800 | 861 | $insertData = substr($insertData, 0, -2) . ')'; |
| 801 | 862 | |
@@ -804,8 +865,9 @@ discard block |
||
| 804 | 865 | |
| 805 | 866 | // Here's where the variables are injected to the query. |
| 806 | 867 | $insertRows = array(); |
| 807 | - foreach ($data as $dataRow) |
|
| 808 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 868 | + foreach ($data as $dataRow) { |
|
| 869 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 870 | + } |
|
| 809 | 871 | |
| 810 | 872 | // Determine the method of insertion. |
| 811 | 873 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -825,15 +887,16 @@ discard block |
||
| 825 | 887 | |
| 826 | 888 | if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
| 827 | 889 | { |
| 828 | - if ($returnmode == 1) |
|
| 829 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 830 | - else if ($returnmode == 2) |
|
| 890 | + if ($returnmode == 1) { |
|
| 891 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 892 | + } else if ($returnmode == 2) |
|
| 831 | 893 | { |
| 832 | 894 | $return_var = array(); |
| 833 | 895 | $count = count($insertRows); |
| 834 | 896 | $start = smf_db_insert_id($table, $keys[0]); |
| 835 | - for ($i = 0; $i < $count; $i++ ) |
|
| 836 | - $return_var[] = $start + $i; |
|
| 897 | + for ($i = 0; $i < $count; $i++ ) { |
|
| 898 | + $return_var[] = $start + $i; |
|
| 899 | + } |
|
| 837 | 900 | } |
| 838 | 901 | return $return_var; |
| 839 | 902 | } |
@@ -851,8 +914,9 @@ discard block |
||
| 851 | 914 | */ |
| 852 | 915 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 853 | 916 | { |
| 854 | - if (empty($log_message)) |
|
| 855 | - $log_message = $error_message; |
|
| 917 | + if (empty($log_message)) { |
|
| 918 | + $log_message = $error_message; |
|
| 919 | + } |
|
| 856 | 920 | |
| 857 | 921 | foreach (debug_backtrace() as $step) |
| 858 | 922 | { |
@@ -871,12 +935,14 @@ discard block |
||
| 871 | 935 | } |
| 872 | 936 | |
| 873 | 937 | // A special case - we want the file and line numbers for debugging. |
| 874 | - if ($error_type == 'return') |
|
| 875 | - return array($file, $line); |
|
| 938 | + if ($error_type == 'return') { |
|
| 939 | + return array($file, $line); |
|
| 940 | + } |
|
| 876 | 941 | |
| 877 | 942 | // Is always a critical error. |
| 878 | - if (function_exists('log_error')) |
|
| 879 | - log_error($log_message, 'critical', $file, $line); |
|
| 943 | + if (function_exists('log_error')) { |
|
| 944 | + log_error($log_message, 'critical', $file, $line); |
|
| 945 | + } |
|
| 880 | 946 | |
| 881 | 947 | if (function_exists('fatal_error')) |
| 882 | 948 | { |
@@ -884,12 +950,12 @@ discard block |
||
| 884 | 950 | |
| 885 | 951 | // Cannot continue... |
| 886 | 952 | exit; |
| 953 | + } elseif ($error_type) { |
|
| 954 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 955 | + } else { |
|
| 956 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 957 | + } |
|
| 887 | 958 | } |
| 888 | - elseif ($error_type) |
|
| 889 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 890 | - else |
|
| 891 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 892 | -} |
|
| 893 | 959 | |
| 894 | 960 | /** |
| 895 | 961 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -906,10 +972,11 @@ discard block |
||
| 906 | 972 | '\\' => '\\\\', |
| 907 | 973 | ); |
| 908 | 974 | |
| 909 | - if ($translate_human_wildcards) |
|
| 910 | - $replacements += array( |
|
| 975 | + if ($translate_human_wildcards) { |
|
| 976 | + $replacements += array( |
|
| 911 | 977 | '*' => '%', |
| 912 | 978 | ); |
| 979 | + } |
|
| 913 | 980 | |
| 914 | 981 | return strtr($string, $replacements); |
| 915 | 982 | } |
@@ -923,8 +990,9 @@ discard block |
||
| 923 | 990 | */ |
| 924 | 991 | function smf_is_resource($result) |
| 925 | 992 | { |
| 926 | - if ($result instanceof mysqli_result) |
|
| 927 | - return true; |
|
| 993 | + if ($result instanceof mysqli_result) { |
|
| 994 | + return true; |
|
| 995 | + } |
|
| 928 | 996 | |
| 929 | 997 | return false; |
| 930 | 998 | } |