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

180
Visualizações
Unexpected results in brower when using pdo_mysql

My code is very simple. I'm attempting to connect to a MySQL instance using pdo_mysql functions. I'm thinking there is a syntax error but the dozens of websites I researched doesn't help me identify it. Below is my code and what is presented on the webpage. Can someone give me some direction?

*** I tried to insert some sites but the app is not letting me.

The pdo_mysql extension is enabled and is displayed in phpinfo.php.

I'm using PHP 7.1.4 on a Windows Server 2012R2 with IIS 8.5

FastCGI is enabled.

Here is my code:

<?php
$username = "myusername";
$password = "mypassword"
$dbname = "mysql"
$hostname = "myserver"
$query = "select user,host from mysql.user";
try {
    $dbconn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
$dbconn = null;
?>

The results on the webpage is:

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $dbconn = null; ?> 
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Based on the fact that your webpage is outputting all of the text after the >, I'm inclined to think that this file is being interpreted as an HTML document, rather than being processed as PHP.

If you view the source for the web page, I would bet that you would see everything from <?php to $dboconn-> in the source, but treated as one long html element.

The obvious thing to check first is if the file has a .php extension. If not, then you'll need to dig into why your server is not executing .php files.

over 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