Jump to content

PHP 5.3.2 (cli) Operation PDO objects showing wrong results


ramjosh

Recommended Posts

Our product is running on LAMP(PHP) architecture. For MySQL operation PDO library has been used.

 

We are in the process of moving the product to a new Linux server.

On the new server we are facing MySQL query output related issue. At the end of the post I have listed the server configuration details of both the servers and the sample PHP program with the output.

 

It works fine in server 1 but when the same code moved to Server 2, the output is not correct.

 

Would appreciate any points to solve this problem

 

The following piece of code is tested and output is also given.

 

<?php

 

/*** mysql hostname ***/

$hostname = 'localhost';

 

/*** mysql username ***/

$username = 'ram';

 

/*** mysql password ***/

$password = 'tellmehow';

 

try {

      $dbh = new PDO("mysql:host=$hostname;dbname=inhouse", $username, $password);

 

      $sql = "SELECT first_name,last_name,user_id,email FROM users LIMIT 1";

      $stmt = $dbh->prepare($sql,array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE));

      $stmt->execute();

      $result = $stmt->fetch(PDO::FETCH_OBJ);

      $stmt->closeCursor();

      /*foreach($result as $key=>$val)

      {

              echo $key.' - '.$val.'<br />';

      }*/

      print_r($result);

      $dbh = null;

  }

  catch(PDOException $e)

  {

      echo $e->getMessage();

  }

?>

 

 

Output for server 1:

 

stdClass Object

(

  [first_name] => super

  [last_name] => admin

  [user_id]=>1

  => [email protected]

)

 

output for server 2:

 

stdClass Object

(

  [first_name] => super

  [last_name] => admin

  [users] => [email protected]

)

 

On server 2 I am not getting the output for field 'user_id' from the table 'users'.

 

For the field 'email' from 'users' table, it is displaying the name of the table itself (users). Not sure what is wrong.

 

The configuration of the servers are given below

Server 1

--------

OS Details:

Linux 2.6.9-5.ELsmp

 

PHP Details:

PHP 5.2.3 (cli) (built: Aug 28 2007 11:48:30)

Copyright © 1997-2007 The PHP Group

Zend Engine v2.2.0, Copyright © 1998-2007 Zend Technologies

  with Suhosin v0.9.22, Copyright © 2007, by SektionEins GmbH

 

PDO details:

PDO

PDO support => enabled

PDO drivers => sqlite2, sqlite, mysql

PDO Driver for MySQL, client library version => 5.0.37

PDO Driver for SQLite 3.x => enabled

 

 

 

Server 2

---------

OS Details:

Linux 2.6.18-8.el5

 

PHP Details:

eAccelerator requires Zend Engine API version 220060519.

The Zend Engine API version 220090626 which is installed, is newer.

Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator.

 

PHP 5.3.2 (cli) (built: Jul  6 2010 17:57:31)

Copyright © 1997-2010 The PHP Group

Zend Engine v2.3.0, Copyright © 1998-2010 Zend Technologies

 

 

PDO Details:

PDO

PDO support => enabled

PDO drivers => mysql, sqlite, sqlite2

PDO Driver for MySQL => enabled

PDO Driver for SQLite 3.x => enabled

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.