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 6679431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:30+00:00 2026-05-26T04:21:30+00:00

I am having a weird issue with PDO when I query a DB2 database

  • 0

I am having a weird issue with PDO when I query a DB2 database using ODBC. I am using PHP 5.3.8 compiled using DB2 Express-C V9.7. The result set always returns dual values for each column. Here’s the code:

$pdo = new PDO("odbc:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=xxxx; HOSTNAME=x.y.z.a;PORT=xxxxx;CurrentSchema=xxx;", "username", "password");

$sql = 'select * from cust_div where cust_no = '.$params.';';

$stmt = $pdo->prepare($sql);
$stmt->execute();

$result = $stmt->fetchAll();

$stmt->closeCursor();

var_dump($result) always returns dual values:

array(1) {
  [0]=>
  array(52) {
    ["CUST_NO"]=>
    string(9) "226622249"
    [0]=>
    string(9) "226622249"
    ["DIV_ID"]=>
    string(1) "P"
    [1]=>
    string(1) "P"

    etc.

What am I doing wrong here?

  • 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-26T04:21:31+00:00Added an answer on May 26, 2026 at 4:21 am

    This is defined behavior for PDO. The array (for each row) returned by fetch() or fetchAll() contains data indexed by column name and order in the table.

    If you don’t want the numerically indexed results you can add the PDO::FETCH_ASSOC constant to your call to fetch:

    $stmt->fetch(PDO::FETCH_ASSOC); //Just column names and values
    //OR
    $stmt->fetchAll(PDO::FETCH_ASSOC);
    

    The default value for this first parameter (which PHP.net calls fetch style) is PDO::FETCH_BOTH which returns both PDO::FETCH_ASSOC and PDO::FETCH_NUM. More can be found on these return styles on the fetch() doc page.

    For the table below and the query SELECT * FROM cust:

    +--+----+
    |id|name|
    +--+----+
    |0 |John|
    +--+----+
    |1 |Jill|
    +--+----+
    

    Calling $stmt->fetchAll(PDO::FETCH_ASSOC); would return:

    array(0=>array(
        'id' => 0,
        'name' => 'John'
    ), 1=>array(
        'id' => 1,
        'name' => 'Jill'
    ));
    

    While calling $stmt->fetch(PDO::FETCH_NUM); would return:

    array(0=>array(
        0 => 0,
        1 => 'John'
    ), 1=>array(
        0 => 1,
        1 => 'Jill'
    ));
    

    The default (PDO::FETCH_BOTH), which is what you’ve encountered, returns a combination of both of them. Since it is the default, it is used when no style is passed:

    $stmt->fetch();
    

    Or when it is explicitly provided:

    $stmt->fetch(PDO::FETCH_BOTH);

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

Sidebar

Related Questions

I'm having a very weird issue in IE6. If I set a div container
I am having some weird issue here. I have a database table which has
Hello good morning everyone, i am having a weird issue when using imagePickerController. Actually
I'm having a weird issue in a program I'm developing for .NET 3.5 using
I'm having a weird issue with Visual Studio 2008. Every time I fire it
I'm having a weird issue with a function I'm trying to call from within
I'm having a weird issue that I can't track down... For context, I have
I'm having a really weird issue with a background worker in one of my
This is a really weird issue I'm having and I'm not really sure what
Having a weird issue. I'm new to Macs and have a windows VM that

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.