Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

657
Visualizações
SQL Connection error: Connection failed: Unknown MySQL server host 'localhost:3306' (0)

I am not sure why I am getting this connection failed error. I am sure that the sever where the database is located is "localhost:3306". I'm currently using cPanel to access myAdmin.

My php code is

<?php

$server = "localhost:3306";
$username="root";
$password="";
$dbname ="mommyinfo";

$conn = new mysqli($server, $username, $password, $dbname);

if ($conn-> connect_error){
    die("Connection failed:  " . $conn->connect_error);
}

$sql = "SELECT title, dateposted FROM post";
$result = $conn->query($sql);

if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo $row["title"] . $row["dateposted"] . "<br>";
    }
}else {
    echo "More posts coming soon!";
}

$conn->close();
?>

At the top of PHP My Admin it says: Server: localhost:3306 »Database: mommyinfo »Table: post

My goal is to get the five most recent posts to display in a div on my website. I've looked it up and I can't seem to find an answer that fixes it. Thanks in advance!

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Remove the port number from the configuration file , just keep the mysql server as localhost and then try.

about 4 years ago · Santiago Trujillo Relatório

0

The tasks are:

  • restart your server.
  • You review if the service the mysql is starting
  • you quit the port
  • Or verify with ip address without any port or verify your port
  • If in services don't restarting else you stop the mysql server
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda