X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FDBA.php;h=c0b783c29dccc6e8101b94e080c992a5cfa73083;hb=ab5cedfa507a85a5622d1830e519c52dfd4e5b5a;hp=bc13b7507739b2ed1c0645c877ef64b79562e353;hpb=0ec44f3e8a73229c3aadea86f61b5571a701c6b7;p=friendica.git diff --git a/src/Database/DBA.php b/src/Database/DBA.php index bc13b75077..c0b783c29d 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -216,7 +216,7 @@ class DBA } $r = self::p("EXPLAIN ".$query); - if (!self::is_result($r)) { + if (!self::isResult($r)) { return; } @@ -251,11 +251,15 @@ class DBA } public static function escape($str) { - switch (self::$driver) { - case 'pdo': - return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1); - case 'mysqli': - return @self::$connection->real_escape_string($str); + if (self::$connected) { + switch (self::$driver) { + case 'pdo': + return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1); + case 'mysqli': + return @self::$connection->real_escape_string($str); + } + } else { + return str_replace("'", "\\'", $str); } } @@ -269,7 +273,7 @@ class DBA switch (self::$driver) { case 'pdo': $r = self::p("SELECT 1"); - if (self::is_result($r)) { + if (self::isResult($r)) { $row = self::toArray($r); $connected = ($row[0]['1'] == '1'); } @@ -1054,7 +1058,12 @@ class DBA $commands[$key] = ['table' => $table, 'conditions' => $conditions]; - $cascade = defaults($options, 'cascade', true); + // Don't use "defaults" here, since it would set "false" to "true" + if (isset($options['cascade'])) { + $cascade = $options['cascade']; + } else { + $cascade = true; + } // To speed up the whole process we cache the table relations if ($cascade && count(self::$relation) == 0) { @@ -1582,7 +1591,7 @@ class DBA * * @return boolean Whether $array is a filled array or an object with rows */ - public static function is_result($array) + public static function isResult($array) { // It could be a return value from an update statement if (is_bool($array)) { @@ -1604,13 +1613,13 @@ class DBA * @param boolean $add_quotation add quotation marks for string values * @return void */ - private static function esc_array_callback(&$value, $key, $add_quotation) + private static function escapeArrayCallback(&$value, $key, $add_quotation) { if (!$add_quotation) { if (is_bool($value)) { $value = ($value ? '1' : '0'); } else { - $value = dbesc($value); + $value = self::escape($value); } return; } @@ -1620,7 +1629,7 @@ class DBA } elseif (is_float($value) || is_integer($value)) { $value = (string) $value; } else { - $value = "'" . dbesc($value) . "'"; + $value = "'" . self::escape($value) . "'"; } } @@ -1631,8 +1640,8 @@ class DBA * @param boolean $add_quotation add quotation marks for string values * @return void */ - public static function esc_array(&$arr, $add_quotation = false) + public static function escapeArray(&$arr, $add_quotation = false) { - array_walk($arr, 'self::esc_array_callback', $add_quotation); + array_walk($arr, 'self::escapeArrayCallback', $add_quotation); } }