1. <tfoot id='tcRu0'></tfoot>
    2. <legend id='tcRu0'><style id='tcRu0'><dir id='tcRu0'><q id='tcRu0'></q></dir></style></legend>

      <small id='tcRu0'></small><noframes id='tcRu0'>

      <i id='tcRu0'><tr id='tcRu0'><dt id='tcRu0'><q id='tcRu0'><span id='tcRu0'><b id='tcRu0'><form id='tcRu0'><ins id='tcRu0'></ins><ul id='tcRu0'></ul><sub id='tcRu0'></sub></form><legend id='tcRu0'></legend><bdo id='tcRu0'><pre id='tcRu0'><center id='tcRu0'></center></pre></bdo></b><th id='tcRu0'></th></span></q></dt></tr></i><div id='tcRu0'><tfoot id='tcRu0'></tfoot><dl id='tcRu0'><fieldset id='tcRu0'></fieldset></dl></div>
        <bdo id='tcRu0'></bdo><ul id='tcRu0'></ul>
    3. 扩展 mysqli_result

      时间:2023-07-29
        <bdo id='4dThK'></bdo><ul id='4dThK'></ul>

            <i id='4dThK'><tr id='4dThK'><dt id='4dThK'><q id='4dThK'><span id='4dThK'><b id='4dThK'><form id='4dThK'><ins id='4dThK'></ins><ul id='4dThK'></ul><sub id='4dThK'></sub></form><legend id='4dThK'></legend><bdo id='4dThK'><pre id='4dThK'><center id='4dThK'></center></pre></bdo></b><th id='4dThK'></th></span></q></dt></tr></i><div id='4dThK'><tfoot id='4dThK'></tfoot><dl id='4dThK'><fieldset id='4dThK'></fieldset></dl></div>

              • <legend id='4dThK'><style id='4dThK'><dir id='4dThK'><q id='4dThK'></q></dir></style></legend>
              • <small id='4dThK'></small><noframes id='4dThK'>

              • <tfoot id='4dThK'></tfoot>
                  <tbody id='4dThK'></tbody>
                本文介绍了扩展 mysqli_result的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我扩展了 PHP 的 mysqli 类,效果很好.但是如何让它在查询时返回自定义结果对象(或用于插入/更新/删除等的布尔值)?

                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 {
                }
                

                这样做我可以返回一个 MySQLiResult 对象,但我无法弄清楚如何为非基于选择的查询返回一个布尔值:

                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);
                }
                

                更新:

                这是我最终使用的:

                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;
                    }
                
                }
                

                推荐答案

                可能最简单的做法是将 MySQLiResult 类视为 mysqli_result 的装饰器.例如

                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.

                这篇关于扩展 mysqli_result的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli_num_rows() 期望参数 1 是 mysqli_result,对象 下一篇:不能在 mysqli_stmt 对象上使用 call_user_func_array

                相关文章

                最新文章

                <legend id='t2G9S'><style id='t2G9S'><dir id='t2G9S'><q id='t2G9S'></q></dir></style></legend>

                1. <i id='t2G9S'><tr id='t2G9S'><dt id='t2G9S'><q id='t2G9S'><span id='t2G9S'><b id='t2G9S'><form id='t2G9S'><ins id='t2G9S'></ins><ul id='t2G9S'></ul><sub id='t2G9S'></sub></form><legend id='t2G9S'></legend><bdo id='t2G9S'><pre id='t2G9S'><center id='t2G9S'></center></pre></bdo></b><th id='t2G9S'></th></span></q></dt></tr></i><div id='t2G9S'><tfoot id='t2G9S'></tfoot><dl id='t2G9S'><fieldset id='t2G9S'></fieldset></dl></div>
                    <bdo id='t2G9S'></bdo><ul id='t2G9S'></ul>
                2. <tfoot id='t2G9S'></tfoot>

                  <small id='t2G9S'></small><noframes id='t2G9S'>