use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
private static $errorno = 0;
private static $affected_rows = 0;
private static $in_transaction = false;
private static $errorno = 0;
private static $affected_rows = 0;
private static $in_transaction = false;
public static function connect($serveraddr, $user, $pass, $db, $install = false) {
if (!is_null(self::$db)) {
public static function connect($serveraddr, $user, $pass, $db, $install = false) {
if (!is_null(self::$db)) {
if ($install) {
if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
if ($install) {
if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
- if (!in_array(strtolower(substr($query, 0, 6)), array("select", "update", "delete"))) {
+ if (!in_array(strtolower(substr($query, 0, 6)), ["select", "update", "delete"])) {
$row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
$row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
* @return string The input SQL string modified if necessary.
*/
public static function clean_query($sql) {
* @return string The input SQL string modified if necessary.
*/
public static function clean_query($sql) {
- $search = array("\t", "\n", "\r", " ");
- $replace = array(' ', ' ', ' ', ' ');
+ $search = ["\t", "\n", "\r", " "];
+ $replace = [' ', ' ', ' ', ' '];
foreach ($params AS $param) {
// Avoid problems with some MySQL servers and boolean values. See issue #3645
if (is_bool($param)) {
foreach ($params AS $param) {
// Avoid problems with some MySQL servers and boolean values. See issue #3645
if (is_bool($param)) {
// There are SQL statements that cannot be executed with a prepared statement
$parts = explode(' ', $orig_sql);
$command = strtolower($parts[0]);
// There are SQL statements that cannot be executed with a prepared statement
$parts = explode(' ', $orig_sql);
$command = strtolower($parts[0]);
- $can_be_prepared = in_array($command, array('select', 'update', 'insert', 'delete'));
+ $can_be_prepared = in_array($command, ['select', 'update', 'insert', 'delete']);
// The fallback routine is called as well when there are no arguments
if (!$can_be_prepared || (count($args) == 0)) {
// The fallback routine is called as well when there are no arguments
if (!$can_be_prepared || (count($args) == 0)) {
if (count($values) > 0) {
array_unshift($values, $params);
if (count($values) > 0) {
array_unshift($values, $params);
$duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr(self::replace_parameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr(self::replace_parameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
$array_element = each($condition);
$array_key = $array_element['key'];
if (!is_int($array_key)) {
$array_element = each($condition);
$array_key = $array_element['key'];
if (!is_int($array_key)) {
}
$stmt = self::select($table, $fields, $condition, ['limit' => 1]);
}
$stmt = self::select($table, $fields, $condition, ['limit' => 1]);
}
// This code works, but is slow
// Bind the result to a result array
}
// This code works, but is slow
// Bind the result to a result array
if ((count($conditions) == 1) && ($field == array_keys($conditions)[0])) {
foreach ($rel_def AS $rel_table => $rel_fields) {
foreach ($rel_fields AS $rel_field) {
if ((count($conditions) == 1) && ($field == array_keys($conditions)[0])) {
foreach ($rel_def AS $rel_table => $rel_fields) {
foreach ($rel_fields AS $rel_field) {
- $retval = self::delete($rel_table, array($rel_field => array_values($conditions)[0]), true, $callstack);
+ $retval = self::delete($rel_table, [$rel_field => array_values($conditions)[0]], true, $callstack);
- $retval = self::delete($table, array($field => $row[$field]), true, $callstack);
+ $retval = self::delete($table, [$field => $row[$field]], true, $callstack);
- public static function update($table, $fields, $condition, $old_fields = array()) {
+ public static function update($table, $fields, $condition, $old_fields = []) {
if (empty($table) || empty($fields) || empty($condition)) {
logger('Table, fields and condition have to be set');
if (empty($table) || empty($fields) || empty($condition)) {
logger('Table, fields and condition have to be set');
$values = array_merge($condition, $fields);
return self::insert($table, $values, $do_insert);
}
$values = array_merge($condition, $fields);
return self::insert($table, $values, $do_insert);
}
if (isset($params['order'])) {
$order_string = " ORDER BY ";
foreach ($params['order'] AS $fields => $order) {
if (isset($params['order'])) {
$order_string = " ORDER BY ";
foreach ($params['order'] AS $fields => $order) {
if (isset($params['limit']) && is_int($params['limit'])) {
$limit_string = " LIMIT " . $params['limit'];
}
if (isset($params['limit']) && is_int($params['limit'])) {
$limit_string = " LIMIT " . $params['limit'];
}