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

  • Home
  • SEARCH
  • 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 705681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:04:51+00:00 2026-05-14T04:04:51+00:00

I have a written a script in PHP that reads from data from a

  • 0

I have a written a script in PHP that reads from data from a MySQL database. I am new to PHP and I have been using the PDO library. I have been developing on a Windows machine using the WAMP Server 2 and all has been working well. However, when I uploaded my script to the LINUX server where it will be used I get the following error when I run my script.

Fatal error: Call to undefined function query()

This is the line where the error is occuring …

foreach($dbconn->query($sql) as $row)

The variable $dbconn is first defined in my dblogin.php include file which I am listing below.

<?php 
// Login info for the database
$db_hostname = 'localhost';
$db_database = 'MY_DATABASE_NAME';
$db_username = 'MY_DATABASE_USER';
$db_password = 'MY_DATABASE_PASSWORD';
$dsn = 'mysql:host=' . $db_hostname . ';dbname=' . $db_database . ';';

try
{
   $dbconn = new PDO($dsn, $db_username, $db_password);
   $dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
  echo 'Error connecting to database: ' . $e->getMessage();
}
?>

Inside the function where the error occurs I have the database connection defined as a superglobal as such …

global $dbconn;

I am a bit confused as to what is happening since all worked well on my development machine. I was wondering if the PDO library was installed but from what I thought it was installed by default as part of PHP v5.

The script is running on an Ubuntu (5.0.51a-3ubuntu5.4) machine and the PHP version is 5.2.4. Thank you for any suggestions. I am really lost on this.

  • 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-05-14T04:04:52+00:00Added an answer on May 14, 2026 at 4:04 am

    Always, but always, develop on the same platform as your production platform. Try your best to mirror the versions of server software (PHP, MySQL, etc). There will always be differences between installs, and especially in the way different OS platforms handle things. Use the old ‘phpinfo()’ script on each server to compare the differences, if any.

    At any rate, even if both the Win and Linux platforms here have the exact same versions of everything, have you checked your configuration? In other words, is the MySQL host name in your DSN a local MySQL host (linked to your Win development platform), or the actual host the Ubuntu server uses? Or are they both "localhost" in either case? Double check this. Also, have you mirrored all data on both servers?

    Do you know for a fact that the Ubuntu server has PDO? You essentially said you assume they are the same. Don’t assume, verify.

    As sobedai mentioned, look at the output of var_dump($dbconn), check that it is actually a PDO object, and go from there.

    This is a typical PDO deployment for me:

    // 'logger' is a custom error logging function with email alerts
    try {
        $dbh= new PDO(dsn);
        if ( is_a($dbh, "PDO") ) {
          $sql= 'SELECT field FROM table';
          $stmt= $dbh->query($sql);
          if ( is_a($stmt, "PDOStatement") ) {
              // handle resultset
          }
          else {
              // weirdness, log it
              logger("Error with statement: {$sql}" .$dbh->errorCode());
          }
        }
        else {
          // some weirdness, log it
          logger('Error making connection: '. $dbh->errorCode());
        }
    }
    catch (PDOException $e) {
      logger('PDOException caught in '.__FILE__.' : '. $e->getMessage());
    }
    catch (Exception $e) {
      logger('General Exception caught in '.__FILE__.' : '. $e->getMessage());
    }
    

    Note I’m using PDO::errorCode in there, referencing the SQL-92 state codes.

    Also, refer to the manual as much as possible.

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See man pages for getpwent. The getpwent() function returns a… May 16, 2026 at 11:12 am
  • Editorial Team
    Editorial Team added an answer Instead of storing the events enacted, an alternative may be… May 16, 2026 at 11:12 am
  • Editorial Team
    Editorial Team added an answer By looking through FormCollection Form only the button that did… May 16, 2026 at 11:12 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have written a PHP script that checks whether a domain is available for
Hey everyone, I have written a script that downloads a zip file from a
How do I delay a PHP script that writes to a text file and
I have a unix command written in a file and I need PHP to
I'm trying to write a jQuery script (I have never written one before and
I'm trying to return json content read from MySQL server. This is supposed to
Assuming the interpreter for the language (Can be anything from PHP to Ruby) is
I'm writing some DB routines and I'm using prepared statements. My environment is PDO
Currently we have a web application written in the providers own proprietary language /
Say I want to have a simple web app that takes some user input,

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.