Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Subs-Db-mysql.php #4065

Merged
merged 5 commits into from Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 9 additions & 11 deletions Sources/Subs-Db-mysql.php
Expand Up @@ -65,11 +65,11 @@ function smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix,
$db_server = 'p:' . $db_server;

$connection = mysqli_init();

$flags = MYSQLI_CLIENT_FOUND_ROWS;

$success = false;

if ($connection) {
if (!empty($db_options['port']))
$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
Expand Down Expand Up @@ -154,7 +154,7 @@ function smf_db_get_server_info($connection = null)

/**
* Callback for preg_replace_callback on the query.
* It allows to replace on the fly a few pre-defined strings, for convenience ('query_see_board', 'query_wanna_see_board'), with
* It allows to replace on the fly a few pre-defined strings, for convenience ('query_see_board', 'query_wanna_see_board', etc), with
* their current values from $user_info.
* In addition, it performs checks and sanitization on the values sent to the database.
*
Expand All @@ -172,11 +172,9 @@ function smf_db_replacement__callback($matches)
if ($matches[1] === 'db_prefix')
return $db_prefix;

if ($matches[1] === 'query_see_board')
return $user_info['query_see_board'];

if ($matches[1] === 'query_wanna_see_board')
return $user_info['query_wanna_see_board'];
foreach (array_keys($user_info) as $key)
if (strpos($key, 'query_') !== false && $key === $matches[1])
return $user_info[$matches[1]];

if ($matches[1] === 'empty')
return '\'\'';
Expand Down Expand Up @@ -254,7 +252,7 @@ function smf_db_replacement__callback($matches)
else
smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
break;

case 'datetime':
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)
return 'str_to_date('.
Expand Down Expand Up @@ -824,7 +822,7 @@ function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $ret
),
$connection
);

if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
{
if ($returnmode == 1)
Expand Down
16 changes: 7 additions & 9 deletions Sources/Subs-Db-postgresql.php
Expand Up @@ -112,7 +112,7 @@ function db_fix_prefix(&$db_prefix, $db_name)

/**
* Callback for preg_replace_callback on the query.
* It allows to replace on the fly a few pre-defined strings, for convenience ('query_see_board', 'query_wanna_see_board'), with
* It allows to replace on the fly a few pre-defined strings, for convenience ('query_see_board', 'query_wanna_see_board', etc), with
* their current values from $user_info.
* In addition, it performs checks and sanitization on the values sent to the database.
*
Expand All @@ -128,11 +128,9 @@ function smf_db_replacement__callback($matches)
if ($matches[1] === 'db_prefix')
return $db_prefix;

if ($matches[1] === 'query_see_board')
return $user_info['query_see_board'];

if ($matches[1] === 'query_wanna_see_board')
return $user_info['query_wanna_see_board'];
foreach (array_keys($user_info) as $key)
if (strpos($key, 'query_') !== false && $key === $matches[1])
return $user_info[$matches[1]];

if ($matches[1] === 'empty')
return '\'\'';
Expand Down Expand Up @@ -210,7 +208,7 @@ function smf_db_replacement__callback($matches)
else
smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
break;

case 'datetime':
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)
return 'to_timestamp('.
Expand Down Expand Up @@ -827,9 +825,9 @@ function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $ret
}
}
}

if ($with_returning && !empty($return_var))
return $return_var;
return $return_var;
}

/**
Expand Down