Warning: mysqli_real_escape_string() expects Parameter 1 to be mysqli

Asked

Viewed 153 times

0

I migrated the site from Ocaweb to hostgator and php are in different versions. Now I need to use mysqli. I’ve already arranged the /public_html/.../mysql.php. Now this file: /home3/.../Phpfrodo.class.php has this error.

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in /home3/.../PHPFrodo.class.php on line 1951

From what I understand, it is necessary to pass a connection as first parameter, but I do not know how to do.

Part of line code 1951:

public function post2Query( $arr2query )
{
    try
    {
        if ( !is_array( $arr2query ) || empty( $arr2query ) )
        {
            throw new Exception( 'post2query: O paramêtro não é um array ou está vazio!' );
        }
        else
        {
            foreach ( $arr2query as $key => $value )
            {
                $value = mysqli_real_escape_string( $this->dbase, $value); // <== linha 1951
                $this->post_fields[] = trim( "$key" );
                $this->post_values[] = trim( "$value" );
                //$this->post_values[] = preg_replace('/\s+/', ' ', $value);
            }
        }
    }
    catch ( Exception $e )
    {
        echo $e->getMessage();
        exit;
    }
    return $this;
}

I believe that the $this->dbase is being declared in the code below. The error happens when trying to include information via Dashboard.

public function database( $dbase = 'default' )
    {
        try
        {
            if ( $dbase != null )
            {
                $this->dbase = $dbase;
            }
            if ( file_exists( DATABASEDIR . 'database.conf.php' ) )
            {
                include DATABASEDIR . 'database.conf.php';
            }
            else
            {
                throw new Exception( "database: Arquivo de configuração do banco inexistente!" );
            }
            if ( !isset( $databases["$this->dbase"] ) )
            {
                throw new Exception( "database: banco [$this->dbase] não configurado em " . DATABASEDIR . "database.conf.php" );
            }
            //conexao adapters
            $this->adapter( $databases[$this->dbase]['driver'] );
            $this->objBanco = new $this->adapter( $databases[$this->dbase] );
            $this->dbname = $databases[$this->dbase]['dbname'];
            $this->sgbd = $databases[$this->dbase]['driver'];
        }
        catch ( Exception $e )
        {
            echo $e->getMessage();
            exit;
        }
        return $this;
    }
  • 1

    What is the value of $this->dbase?

  • I edited the post, @Andersoncarloswoss, would that be the part? In the same folder there is a file called Conexao.class.php. Which, from what I understand, makes a connection with the BD, do I have to call a connection variable with the BD of that file? Error is happening when trying to include data via Dashboard/admin.

  • The function you are using expects an instance of mysqli; what you’re going through is a string with the access configuration.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.