danielholmes/bga-workbench

Make ->fetch_assoc() callable on APP_DbObject::DbQuery

Lucas-C opened this issue · 6 comments

Hi.

In the BGA framework I often call self::DbQuery("...")->fetch_assoc().

However, the bga-workbench implementation of this method in APP_DbObject.inc.php always returns the rowCount().

Would you agree to remove this ->rowCount() call in APP_DbObject::DbQuery() please ?

Regards

Hi.
Thank you very much for the fast fix !

Sadly, I'd like to reopen this :(

The issue is that the BGA framework clearly uses the mysqli extension.
In order to be fully compatible (and be able to call fetch_assoc()), bga-workbench would have to use it too and not doctrine/dbal :(

I had a quick look at bga-workbench code and the following features would need to be replicated using only mysqli:

What do you think ? Would you agree to drop doctrine ?

I'm OK to submit a PR to start this work.

Some alternatives:

  • find a way to retrieve the mysqli_result from a Doctrine\DBAL\Connection (the underlying driver is pdo_mysql so it should be doable)
  • use a subclasse of Doctrine\DBAL\Connection that implements mysqli_result methods like fetch_assoc
  • just do not support self::DbQuery("...")->fetch_assoc(). There are other ways to query results like you do in BattleForHill218

I don't want to dump doctrine entirely - it gives a nice interface to use in testing. But we could use mysqli directly within the BGA stubbing code. My preferred approach is your first suggestion (work out how to get the same result out of doctrine that fetch_assoc gives).

I can look into this in a few days, but if you can't wait would happily take a PR

PR sent !

Thanks @Lucas-C ! Merged and new version released