"No database Selected" in PHP with Mysql

Asked

Viewed 1,651 times

1

Columns to receive data:

$GravaLinhaBanco = "INSERT INTO `trechosmonitora_cotacao` (`Codigo`, `CodTrecho`, `CodCliente`, `CodLoja`, `Url`, `Rotulo`, `Trecho`, ";
$GravaLinhaBanco = $GravaLinhaBanco . "`Origem`, `Destino`, `Tipo`, `Status`, `IdaVolta`, `Antecedencia`, `Permanencia`, `Adultos`, `Criancas`,";
$GravaLinhaBanco = $GravaLinhaBanco . " `Bebes`, `ServidorMonitorando`, `SituacaoMonitoramento`, `Data_Monitoramento`, `Data_Monitorado`, ";
$GravaLinhaBanco = $GravaLinhaBanco . "`Hora_Inicio`, `Hora_Fim`, `TrackTrechos`, `VooaVoo`, `TarifaCompleta`)";
#DADOS A SEREM GRAVADOS;
$GravaLinhaBanco = $GravaLinhaBanco . "VALUES('".$codigo."', '".$codTrecho."', '".$codcliente."', '".$codigosite."', '".$url."', '".$rotulo."',";
$GravaLinhaBanco = $GravaLinhaBanco . "'".$trecho."', '".$codorigem."', '".$coddestino."', '".$tipoVoo."', '".$status."', '".$idavolta."', '".$anoantecedencia."',";
$GravaLinhaBanco = $GravaLinhaBanco . "'".$permanencia."', '".$adultos."', '".$criancas."', '".$bebes."', '', '0', '00/00/0000', '00/00/0000', '00:00:00', '00:00:00',";
$GravaLinhaBanco = $GravaLinhaBanco . "'".$TrackTrechos."', 'N', 'S');";
$sql = $GravaLinhaBanco;
$codigo = $codigo + 1;

$NewQuery = mysqli_query($link, $sql) or die(mysqli_error($link));
$NewQuery = mysqli_close($link);
  • 1

    Gustavo the error happens before that code you posted, as you are running the connection to the Bank?

  • 1

    @Gustavo, the error indicates that the database is missing. after using the mysqli_connect function, use mysqli_select_db

  • If the answer solved your problem, please mark as the correct answer.

1 answer

2

The mistake No database selected occurs because a database was not selected to operate.

You can select a bank in two different ways.

Selecting when to connect:

$conexao = mysqli_connect('localhost', 'usuario', 'senha', 'banco');

or after connecting:

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

Browser other questions tagged

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