Error in PHP Code Warning: mysqli_select_db () expects exactly 2 parameters, 1 given [duplicate]

-1

The error of my code is in the Connection to the database, it is the following:

  

mysqli_select_db () expects exactly 2 parameters, 1 given

<?php
   $servidor='localhost';
   $banco='isartes';
   $usuario='root';
   $senha='';
   $conexao=mysqli_connect($servidor,$usuario,$senha);
   if(!($conexao)){
      echo "Conexao Falhada"; exit;
   }
   $selecao = mysqli_select_db($conexao);
   if(!($selecao)){
      echo "Base de dados nao achada";
      exit;
   }
?> 
    
asked by anonymous 03.11.2016 / 15:17

1 answer

0

Most MySQL functions require connection as the first argument. The error indicates that two arguments should be passed, but only one was passed.

There are two ways to solve the problem, the first is to do what the error says, to pass the name of the bank after the connection.

The second is not to use this function and pass the database name as the fourth argument of the mysqli_connect() function.

First form:

$conexao = mysqli_connect($servidor,$usuario,$senha);
mysqli_select_db($conexao, $banco);

Second form:

$conexao = mysqli_connect($servidor,$usuario,$senha, $banco);
    
03.11.2016 / 15:32