-1

Hey i have a problem with my variable. can you help me please ?

Error: Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in \classes.php on line 768

class TDMCore
{

public $rsSQL;
public $isDBCon;
function DBConnect($DBType = 'MODULE')
{
    $S = $this->arConfig[$DBType . '_DB_SERVER'];
    $L = $this->arConfig[$DBType . '_DB_LOGIN'];
    $P = $this->arConfig[$DBType . '_DB_PASS'];
    $DB = $this->arConfig[$DBType . '_DB_NAME'];
    $this->rsSQL = mysqli_connect($S, $L, $P, $DB);
    $Charset = 'utf8';

    if ($this->rsSQL) {
        $this->isDBCon = true;
        mysqli_set_charset($this->rsSQL, $Charset);
        return true;

    }

    if (substr($S, 0, 12) == 'autodbase.ru') {
        $S = 'TDBase';
    }

    $this->arErrors[] = 'Error! No connection to "' . $S . '" ';
    $this->isDBCon = false;
    return false;
}
public function Select($DBTable, $arOrder, $arFilter, $arParams = array())

            $key = mysqli_real_escape_string($this->rsSQL, $key); - problem line 768
}
  • You should use parameterized prepared statements instead of manually escaping the data like that. Then this would be a non-issue. To answer your question, you need to connect to the database (call your DBConnect()) before using `mysqli_real_escape_string()` – M. Eriksson Feb 02 '19 at 18:31
  • 2
    http://php.net/manual/en/mysqli.quickstart.prepared-statements.php – Pinke Helga Feb 02 '19 at 18:33
  • However, the issue will still be similar when using prepared statements. For some reason `$this->rsSQL` is not a mysqli object when calling `TDMCore::Select`. The code snippet does not show why. – Pinke Helga Feb 02 '19 at 18:37
  • You need to ensure you call `DBConnect()` before `Select()` as the connection is set in there. Although you should read about [dependency injection](https://stackoverflow.com/questions/10064970/php-dependency-injection) – Nigel Ren Feb 02 '19 at 18:38

1 Answers1

0
global  $isDBCon;
global  $rsSQL;

This should do it