Extended MySQLi class

Posted on 2011-10-14
Last Modified: 2012-05-12
Hi! I'm looking for a good, clean, easy to use mysqli wrapper class that will return associative arrays, etc. Unfortunately, I don't think I have the time to write one myself. Is there anything like that, that you know of, available?
Question by:Julian Matz
    LVL 107

    Expert Comment

    by:Ray Paseur
    LVL 21

    Author Comment

    by:Julian Matz
    Yes, but I'd like to be able to do something like this:

    $sql = new mysqli_extended();
    $result = $sql->query( "SELECT * FROM table" );

    print_r( $result );

    -- which would print out an associative array for me. In other words, the class would be able to distinguish between SELECT and INSERT or UPDATE queries. Does that make sense?

    LVL 107

    Expert Comment

    by:Ray Paseur
    I think the part about understanding the difference between SELECT, INSERT and UPDATE is fairly easy.  But the results set from a SELECT is not an associative array.  It's a resource that gives you access to a collection of rows.  Each row is an associative array.  The results set may contain zero, one or many rows.  

    If you wanted to retrieve all of the rows at once, you could return them in a two-dimensional array with something like this (but that is kind of awkward in my opinion):

    $allrows = array();
    while ($row = mysqli_fetch_assoc($resource))
        $allrows[] = $row;
    LVL 1

    Accepted Solution

    Might want to look at:


    If you really want to get hard core you could also use Doctrine:
    LVL 21

    Author Comment

    by:Julian Matz
    Thanks, Ray, I know that. It's just I was wondering if there was a class out there somewhere that would do some of the "heavy lifting" for me - e.g. return a two-dimensional array in the case of a SELECT query, and maybe just TRUE or FALSE in the case of DELETE, and maybe (int)$mysqli->affected_rows for an UPDATE or INSERT, etc.

    Thanks, Bryan, will have a look at those.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now