Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:03:25+00:00 2026-06-10T00:03:25+00:00

I have a file on my server called test.php. Here are the contents: <?php

  • 0

I have a file on my server called test.php. Here are the contents:

<?php
echo "hi\n";
try {
    $dbh = new PDO('mysql:host=localhost;dbname=db', "foo", "bar");
    echo "hi\n";
} catch (PDOException $e) {
    die("Error!");
}
echo "hi\n";
?>

The code is fairly straightforward. It should print hi three times if everything works out.

When I run this code from the shell, it does indeed print “hi” on three separate lines. However, when I access this file through the website (http://localhost/test.php), it only prints one hi.

Removing $dbh = new PDO(‘mysql:host=localhost;dbname=db’, “foo”, “bar”); causes all three his to print successfully via website.

The MySQL information is correct and the user does have access to the database.

What would cause me accessing the file directly through the shell to print all three times, but only print once when accessed via the website?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:03:26+00:00Added an answer on June 10, 2026 at 12:03 am

    Are you sure you have enabled PDO extension? If you get only one “hi” it means that you get fatel error in your PDO object declaration. Something like this "Fatal error: Class 'PDO' not found" Please check.

    http://php.net/manual/en/pdo.installation.php

    Your code works fine on me anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file on my server called pform.php, this is what it looks
I have a file on my server called pform.php, this is what it looks
I have a file called error.log on my server that I need to frequently
I have a file foo.bar.1 on my server and when I try to access
I have a file called generator.php that uses fwrite() to create a result.php on
I have a file called test.csv, Data in the file is looking like this:
I have a file server and wanting to optimize it the best I can,
I have a file on my server that's outside of my app directory. It's
I have to develop a file server service that transfer file form a specified
I have a standard node.js static file server that I want to use to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.