Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!