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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:24:00+00:00 2026-05-22T20:24:00+00:00

I have extended PHP’s mysqli class, which works fine. But how can I make

  • 0

I have extended PHP’s mysqli class, which works fine. But how can I make it return a custom result object (or a boolean for insert/update/delete etc) when querying?

namespace MyApp;
class MySQLi extends \mysqli {
    public function query($query, $resultmode = null) {
        // This needs to return a MySQLiResult or a boolean
    }
}
class MySQLiResult extends \mysqli_result {
}

Doing this I can return a MySQLiResult object, but I can’t figure out how to return a boolean for non select based queries:

public function query($query, $resultmode = null) {
    $this->real_query($query); 
    return new MySQLiResult($this);
}

Update:

This is what I ended up using:

class MySQLi extends \mysqli {

    public function query($query, $resultmode = null) {
        $result = parent::query($query, $resultmode);
        return is_bool($result) ? $result : new MySQLiResult($result);
    }

}


class MySQLiResult {

    private $result;

    public function __construct(mysqli_result $result) {
        $this->result = $result;
    }

    public function __call($name, $arguments) {
        return call_user_func_array(array($this->result, $name), $arguments);
    }

    public function __set($name, $value) {
        $this->result->$name = $value;
    }

    public function __get($name) {
        return $this->result->$name;
    }

}
  • 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-22T20:24:00+00:00Added an answer on May 22, 2026 at 8:24 pm

    Probably the simplest thing to do would be treat your MySQLiResult class as a decorator for mysqli_result. For example

    class MySQLiResult
    {
        private $result;
    
        public function __construct(\mysqli_result $result)
        {
            $this->result = $result;
        }
    }
    

    You could then proxy method calls to the internal result and decorate (add functionality) where required.

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

Sidebar

Related Questions

I have a class named CropImageView which is extended from ImageView . but the
I have a class structure in PHP which I am using to allow for
i have asked the extended permission for user's primary email address. but, i can't
In Ruby, I have a DAO class, which is extended by a class that
I have extended SimpleCursorAdapter and am running into a weird issue with bindView, which
I have a main class and two extended classes: class Main { public $foo;
I'm writing a library in PHP 5.3, the bulk of which is a class
I have a weird problem: I extended Zend_Log with a class called \Application\Log (it
I have a very heavy class definition that's MySQL dependent (i.e. can be slow
I have a primary class and an extended one (database connections). Parent Classname Classica

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.