ERROR MYSQLI BD MIGRATION

Asked

Viewed 36 times

1

FRIENDS , I migrated of vps and after that I started to have problems with the connection of the comic mysql, I made some adjustments now I can not find the error , could help me please , I have a php file that connects to the bank and another that sends the following info .

the mistake is :

Host information: Localhost via UNIX socket # Warning: mysqli_query() expects at least 2 Parameters, 1 Given in /home/factor/public_html/formulario/app/model.php on line 120

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in /home/factor/public_html/formulario/app/model.php on line 121

--php connects to bd--

    <?php
$link = mysqli_connect("localhost", "xxxxx", "xxxxxx", "xxxxxx");

/* check connection */ 
if (!$link) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

printf("Host information: %s\n", mysqli_get_host_info($link));

/* close connection */
mysqli_close($link);
?>

---php data reading ----

function select_empresa()
{
    $sql = "SELECT e.id,e.nome_fantasia 
                FROM empresas e
                LEFT JOIN empresas_acesso ea ON(ea.id_empresa = e.id)
                WHERE ea.status = 1 AND DATE(now()) <= ea.data_expira ORDER BY nome_fantasia ASC";
    if(self::myysqli($sql))
    {
        return $this->resultt(self::myysql($sql));
    }
}

function check_acesso($empresa,$senha)
{
    if($empresa)
    {
        $sql = "SELECT e.id
                    FROM empresas e
                    LEFT JOIN empresas_acesso ea ON(ea.id_empresa = e.id)
                    WHERE ea.status = 1
                    AND e.nome_fantasia = '{$empresa}'";
        if(self::myysql($sql))
        {
            $data = $this->resultt(self::myysql($sql));
            $id = $data[0]->id;

            $senha = stripslashes(trim(str_replace(" ","",$senha)));
            $sql = "SELECT e.nome_fantasia,ea.senha
                        FROM empresas_acesso ea
                        JOIN empresas e ON(e.id = {$id})
                        WHERE ea.id_empresa = {$id}";
            if(self::myysql($sql))
            {
                $data = $this->resultt(self::myysql($sql));
                if($data[0]->senha != $senha)
                    return 501;
                else{
                    session_start();
                    session_destroy();

                    session_start();
                    $_SESSION['SS_empresa_id'] = $id;
                    $_SESSION['SS_empresa'] = $this->reg_caracter($data[0]->nome_fantasia);
                    $_SESSION['SS_start'] = strtotime('+7200 second'); // 2 horas expira sessao
                    header("Location:".SITE_URL."/formulario/entrada");
                    die();
                }   
            }else
                return 500; // empresa desabilitada no sistema
        }
    }
}

function get_dados_formulario()
{
    if($_POST)
    {
        $set_values = $set_fields = $sep = null;
        $set_v_descritores_chaves = $set_f_descritores_chaves = null;
        $set_v_pares_adjetivos = $set_f_pares_adjetivos = null;
        foreach($_POST['data'] AS $k=>$v)
        {
            if(!empty($v))
            {
                $pattern = '/^descritores_chaves/';
                $pattern2 = '/^pares_adjetivos/';
                $pattern_data = '/^data_nascimento/';
                if(preg_match($pattern_data, $k, $matches, PREG_OFFSET_CAPTURE))
                {
                    $v = $this->edit_datatime($v);
                }
                if(preg_match($pattern, $k, $matches, PREG_OFFSET_CAPTURE))
                {
                    $set_v_descritores_chaves = ',"'. self::enter_eval($v) .'"';
                    $set_f_descritores_chaves = ',descritores_chaves';
                }elseif(preg_match($pattern2, $k, $matches, PREG_OFFSET_CAPTURE)){
                    $set_v_pares_adjetivos = ',"'. self::enter_eval($v,1).'"';
                    $set_f_pares_adjetivos = ',pares_adjetivos';
                }else{
                    $v = filter_var($v, FILTER_SANITIZE_STRING);
                    $set_fields .= $sep.$k;
                    $set_values .= $sep.'"'.$v.'"';
                    if(empty($sep)){$sep=',';}
                }
            }
        }

        $set_fields .= $set_f_descritores_chaves;
        $set_values .= $set_v_descritores_chaves;

        $set_fields .= $set_f_pares_adjetivos;
        $set_values .= $set_v_pares_adjetivos;


        $sql = "INSERT INTO cadastros ({$set_fields},data_entrada) VALUES({$set_values},now())";

        //print_r($sql);
        //exit;

        if(self::myysql($sql))
        {
            die('cadastro realizado com sucesso');
        }

    }
}

private static function myysqli($sql)
{
    if($sql)
    {
        mysqli_query("SET NAMES 'UTF8'");   
        return mysqli_query($sql);
    }
}

private function resultt($sql)
{
    if($sql)
    {
        while($row = mysql_fetch_object($sql))
        {
            $data[] = $row;
        }
        return $data;
    }
}

private static function enter_eval($array,$fk)
{
    $array_data = $sep = null;
    if($array)
    {
        foreach($array AS $k=>$v)
        {
            if(!empty($fk))$v = (empty($v))?100:$v;
            $v = filter_var($v, FILTER_SANITIZE_STRING);
            $array_data .= $sep."'".($k)."'=>'".$v."'"; 
            if(empty($sep)){$sep=',';}
        }
        return $array_data;
    }
}

private function edit_datatime($value)
{
    if($value)
    {
        $value = explode('/',$value);
        $value = $value[2].'-'.$value[1].'-'.$value[0];
        return $value;
    }
}

private function reg_caracter($string){ 
    $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ,./*'; 
    $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr    '; 
    $string = utf8_decode($string);     
    $string = strtr($string, utf8_decode($a), $b); 
    $string = strtolower($string); 
    return filter_var(stripslashes(trim(preg_replace('/\s+/','',strtolower($string)))),FILTER_SANITIZE_STRING); 
} 

}

1 answer

0

Good afternoon my dear!

The error is clear, the function mysqli_query() requires 2 parameters. One is the connection, the other is the query you want to run. Example:

$link = mysqli_connect('localhost', 'user', 'password', 'dbname');

$sql = 'SELECT * FROM table';

$result = mysql_query( $link, $sql );

An error I saw in your file is also that in your connection file you close the connection with the bank without at least using it. Remove the part of the mysqli_close() only use after you finish running the query, remembering that every time you have to take information from the bank you will have to re-establish the connection with the bank for consultation.

If it doesn’t work, please comment.

Browser other questions tagged

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