Call to undefined function query() - using PDO in PHP

Posted by webworm on Stack Overflow See other posts from Stack Overflow or by webworm
Published on 2010-03-30T18:40:03Z Indexed on 2010/03/30 18:43 UTC
Read the original article Hit count: 573

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo