Search code examples
phpmysqlipdodatabase-performancesqlperformance

Mysqli dynamic query bind_results


I wrote one databasse class which I use often and I used mysqli.I wanted to write it with PDO but it was slow (It is not about ip connection :) ),and my website is really huge and this pdo little slowness will be really big problem,that's why I choosed difficult way --Mysqli--.I wrote some dynamic class which bind params dynamicly and easily usage like this:

DB::getInstance()->query(sql,'ss',array($a,$b));

This was really useful untill today.I wanted to get result and also count values but I discover reaally big problem that when I use num_rows mysqli get_result will not work,When I use get_result num rows will never work,also when I use get_result and if I want to use it again for same query second one will not work .Also get_result is not good function because it support only mysqlid.Then I have tried bind result which is useless because every select query I should write bind_result(params) which is not good for other developers on company also.What Should I do?Pdo is slow and for my website it is really slow,mysqli is not for developers it increase development time.How can I bind results dinamicly for query?I want something like I will write sql statement and bind result should get column names dinamicly bind them aoutomaticly and then I will write fetch() and I will write column names and I will get result.How can I do that?


Solution

  • When I use get_result num rows will never work

    this is not true
    besides, you never need num rows anyway

    when I use get_result and if I want to use it again for same query

    you don't want it

    get_result is not good function because it support only mysqlid

    this is true
    however, if your site is so big and distinct, there is no problem to install a required module or two.

    How can I bind results dinamicly for query?

    use get_result.

    To reuse a result get all the rows into array using fetch_all() and then use this array anywhere you wish

    Instead of num_rows just fetch the data and see whether anything was fetched or not.