CodeIgniter Forums
[SOLVED] How to change db connection in CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Best Practices (https://forum.codeigniter.com/forum-12.html)
+--- Thread: [SOLVED] How to change db connection in CI (/thread-69916.html)



[SOLVED] How to change db connection in CI - plonknimbuzz - 01-30-2018

i want to dump my old db to my new db design which have different stucture.
i dump all my table and save query using get_compiled_insert() to file.

the problem is my old db is sql server and my new db is mysql

example
$this->db->set(['id'=>1, 'name'=>'john'])->get_compiled_insert('table');

result : INSERT INTO "table" ("id", "name") VALUES ('1', 'john')


this is valid sql server query but not in mysql, because the right query in mysql is: INSERT INTO `table` (`id`, `name`) VALUES ('1', 'john')

conclusion:
script: $this->db->set(['id'=>1, 'name'=>'john'])->get_compiled_insert('table');
with sql server connection: INSERT INTO "table" ("id", "name") VALUES ('1', 'john')
with mysql connection: INSERT INTO `table` (`id`, `name`) VALUES ('1', 'john')

what i want is dump sql server data to build mysql query. 
i really can solve this with my own code (build query manually), but i want to do the right way in CI.

How to do this in the right way(best practice)?
maybe i can dump the data using sql server connection and build compiled query using mysql connection.
thanks


RE: How to change db connection in CI - plonknimbuzz - 01-30-2018

SOLVED: https://www.codeigniter.com/userguide3/database/connecting.html

thanks


RE: [SOLVED] How to change db connection in CI - Narf - 01-30-2018

(01-30-2018, 02:26 AM)plonknimbuzz Wrote: this is valid sql server query but not in mysql, because the right query in mysql is: INSERT INTO `table` (`id`, `name`) VALUES ('1', 'john')

That's not entirely true.

Double quotes are the correct identifier escape character per the SQL standards and MySQL does support that via the ANSI_QUOTES SQL mode.


RE: [SOLVED] How to change db connection in CI - plonknimbuzz - 01-30-2018

(01-30-2018, 06:14 AM)Narf Wrote:
(01-30-2018, 02:26 AM)plonknimbuzz Wrote: this is valid sql server query but not in mysql, because the right query in mysql is: INSERT INTO `table` (`id`, `name`) VALUES ('1', 'john')

That's not entirely true.

Double quotes are the correct identifier escape character per the SQL standards and MySQL does support that via the ANSI_QUOTES SQL mode.

Did you mean this?

[Image: hJ5T100.png]

thanks narf, this is new knowledge for me.


RE: [SOLVED] How to change db connection in CI - Narf - 01-31-2018

Possibly, the mode name is ANSI_QUOTES, but phpMyAdmin may be shortening it ... idk.