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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:44:55+00:00 2026-05-16T11:44:55+00:00

I am a little perplexed by the mysqli interface in PHP. When I set

  • 0

I am a little perplexed by the mysqli interface in PHP. When I set out yesterday to change my old mysql code to mysqli, the docs steered me down the road of ::prepare, ::bind_params and ::execute.

In my efforts to deal with the results, I ended up writing my own fetch_assoc – and had problems which I discussed on SO. One commentator queried what I was doing not using ::fetch_assoc. I had not even noticed the mysqli_result class. When I morphed my mysqli code from ::preapre to ::query, the result handling became MUCH easier – with one exception: when previously I used ::bind_results to extract the columns, the PHP associative array that resulted would carry the correct data types; when instead I now use ::fetch_assoc etc, all I get is an array of strings.

I am coding up a converter now. I just thought that since I already committed one cardinal error in my understanding of the mysqli library, I better post here to see whether there’s an "official" way of getting type-congruent associative result arrays.

  • 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-16T11:44:56+00:00Added an answer on May 16, 2026 at 11:44 am

    If you’re using mysqlnd as the transport client and set the option MYSQLI_OPT_INT_AND_FLOAT_NATIVE on the mysqli object you get in fact the native types.

    echo 'phpversion: ', phpversion(), "\n";
    
    $m = new mysqli('localhost', 'localonly', 'localonly', 'test');
    $m->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
    $m->query('CREATE TABLE soTest (x int)');
    $m->query('INSERT INTO soTest (x) VALUES (1),(2)');
    
    $r = $m->query('SELECT x from soTest');
    var_dump($r->fetch_assoc());
    

    prints

    phpversion: 5.3.3
    array(1) {
      ["x"]=>
      int(1)
    }

    This feature has been added in PHP 5.3.


    To get you started with PDO (should you choose to use it):

    <?php
    $pdo = new PDO('mysql:host=localhost;dbname=test', 'localonly', 'localonly');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // the pdo_mysql driver uses emulated prepared statements by default
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    
    // afaik only the mysqlnd client supports native types, with libmysql you'll get only strings/null
    echo 'client: ', $pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), "\n";
    
    // set up test environment
    $pdo->exec('CREATE TEMPORARY TABLE soTest (x int, y varchar(16))');
    $pdo->exec("INSERT INTO soTest (x,y) VALUES (1,'a'),(2,null)");
    
    // statement with positional parameter
    $stmt = $pdo->prepare('SELECT x,y FROM soTest WHERE x>?');
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    
    $stmt->execute( array(0) );
    foreach( $stmt as $row ) {
      foreach( $row as $col ) {
        echo gettype($col), '(', $col, ') ';
      }
      echo "\n";
    }
    

    prints

    client: mysqlnd 5.0.7-dev - 091210 - $Revision: 300533 $
    integer(1) string(a) 
    integer(2) NULL() 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • 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 Triggers and procedures can have be much faster than an… May 16, 2026 at 2:10 pm
  • Editorial Team
    Editorial Team added an answer No, there is no way, and there is no need… May 16, 2026 at 2:10 pm
  • Editorial Team
    Editorial Team added an answer This is acceptable if you'r only ever reading a single… May 16, 2026 at 2:10 pm

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've looked through similar questions but I'm still a little perplexed about something that
When I change the selection in a DropDownList, a PartialView gets updated via a
When supplying dates to a stored procedure via a parameter I'm a little confused
This should work, so I'm really perplexed about why it's not working. I'm checking
I am new to python and would appreciate a little help. How does one
Little bit confused... I am trying to track mailto links being clicked, but constantly
This little search example works but only the first time. How do I clear
This little function checks a (finite) Brainfuck string for validity. It check's whether the
A little while back (after recently installing VStudio 2010) I used the Go to
first a little bit of documentation from the jQuery validation plugin: Use submitHandler 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.