Skip to content

Commit

Permalink
[3.10] [PHP 8.1] Mysqli database driver escape function fix (joomla#3…
Browse files Browse the repository at this point in the history
…6787)

* [3.10] [PHP 8.1] Mysqli database driver escapt function fix

Fixes `Deprecated: mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated in libraries/joomla/database/driver/mysqli.php on line 254`

* Fix also the other db drivers

Co-authored-by: Richard Fath <[email protected]>
  • Loading branch information
beat and richard67 authored Jan 23, 2022
1 parent 3de1ce1 commit a03c3f1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libraries/joomla/database/driver/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ public function escape($text, $extra = false)
if (is_float($text))
{
// Force the dot as a decimal point.
return str_replace(',', '.', $text);
return str_replace(',', '.', (string) $text);
}

$this->connect();

$result = mysql_real_escape_string($text, $this->getConnection());
$result = mysql_real_escape_string((string) $text, $this->getConnection());

if ($extra)
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/joomla/database/driver/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public function escape($text, $extra = false)
if (is_float($text))
{
// Force the dot as a decimal point.
return str_replace(',', '.', $text);
return str_replace(',', '.', (string) $text);
}

$this->connect();

$result = mysqli_real_escape_string($this->getConnection(), $text);
$result = mysqli_real_escape_string($this->getConnection(), (string) $text);

if ($extra)
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/joomla/database/driver/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ public function escape($text, $extra = false)
if (is_float($text))
{
// Force the dot as a decimal point.
return str_replace(',', '.', $text);
return str_replace(',', '.', (string) $text);
}

$text = str_replace("'", "''", $text);
$text = str_replace("'", "''", (string) $text);

return addcslashes($text, "\000\n\r\\\032");
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/database/driver/pdomysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function escape($text, $extra = false)
if (is_float($text))
{
// Force the dot as a decimal point.
return str_replace(',', '.', $text);
return str_replace(',', '.', (string) $text);
}

$this->connect();
Expand Down
4 changes: 2 additions & 2 deletions libraries/joomla/database/driver/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ public function escape($text, $extra = false)
if (is_float($text))
{
// Force the dot as a decimal point.
return str_replace(',', '.', $text);
return str_replace(',', '.', (string) $text);
}

$this->connect();

$result = pg_escape_string($this->connection, $text);
$result = pg_escape_string($this->connection, (string) $text);

if ($extra)
{
Expand Down

0 comments on commit a03c3f1

Please sign in to comment.