CodeIgniter Forums
Any way to use the query builder without a database connection? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Any way to use the query builder without a database connection? (/showthread.php?tid=73162)



Any way to use the query builder without a database connection? - trentwritescode - 03-25-2019

Hi All -


I'm hoping to use the CI query builder (we're in v3) to generate SQL statements. The only problem is that we don't actually have a connection to run them in. Our application sends queries via a web service to have them run against a cloud-hosted MySQL instance (passing the select statement as the HTTP body).

Is there any way to use CI's query builder to simply generate the SQL statement and to return the assembled statements as strings?

Thanks in advance -

Trent


RE: Any way to use the query builder without a database connection? - php_rocs - 03-25-2019

@trentwritescode,

Checkout the $this->db->get_compiled_select() [link: https://codeigniter.com/user_guide/database/query_builder.html?highlight=query%20builder#selecting-data ] feature.


RE: Any way to use the query builder without a database connection? - trentwritescode - 03-25-2019

(03-25-2019, 10:56 AM)php_rocs Wrote: @trentwritescode,

Checkout the $this->db->get_compiled_select() [link: https://codeigniter.com/user_guide/database/query_builder.html?highlight=query%20builder#selecting-data ] feature.

Unfortunately, this requires a properly-configured database connection –– something we do not have.


RE: Any way to use the query builder without a database connection? - ciadmin - 03-25-2019

The framework unit testing has a mock database that might be the trick...
https://github.com/codeigniter4/CodeIgniter4/tree/develop/tests/_support/Database


RE: Any way to use the query builder without a database connection? - trentwritescode - 03-25-2019

I'll keep this in mind when we moved to CI4. Thanks!