CI link MySQL and MSSQL

Source: Internet
Author: User
Because of the comparison between MSSQL and MySQL data, so.
Configuration: database.php

$db['default']['hostname'] = '192.168.1.222';$db['default']['username'] = 'root';$db['default']['password'] = 'test';$db['default']['database'] = 'demo_database';$db['default']['dbdriver'] = 'mysql';$db['default']['dbprefix'] = 'iwebshop_';$db['default']['pconnect'] = TRUE;$db['default']['db_debug'] = TRUE;$db['default']['cache_on'] = FALSE;$db['default']['cachedir'] = '';$db['default']['char_set'] = 'utf8';$db['default']['dbcollat'] = 'utf8_general_ci';$db['default']['swap_pre'] = '';$db['default']['autoinit'] = TRUE;$db['default']['stricton'] = FALSE;$db['default']['hostname'] = '192.168.1.222';$db['default']['username'] = 'sa';$db['default']['password'] = 'test';$db['default']['database'] = 'demo_database';$db['default']['dbdriver'] = 'sqlsrv';$db['default']['dbprefix'] = '';$db['default']['pconnect'] = TRUE;$db['default']['char_set'] = 'utf-8';

Just don't know how to call?

Reply content:

Because of the comparison between MSSQL and MySQL data, so.
Configuration:database.php

$db['default']['hostname'] = '192.168.1.222';$db['default']['username'] = 'root';$db['default']['password'] = 'test';$db['default']['database'] = 'demo_database';$db['default']['dbdriver'] = 'mysql';$db['default']['dbprefix'] = 'iwebshop_';$db['default']['pconnect'] = TRUE;$db['default']['db_debug'] = TRUE;$db['default']['cache_on'] = FALSE;$db['default']['cachedir'] = '';$db['default']['char_set'] = 'utf8';$db['default']['dbcollat'] = 'utf8_general_ci';$db['default']['swap_pre'] = '';$db['default']['autoinit'] = TRUE;$db['default']['stricton'] = FALSE;$db['default']['hostname'] = '192.168.1.222';$db['default']['username'] = 'sa';$db['default']['password'] = 'test';$db['default']['database'] = 'demo_database';$db['default']['dbdriver'] = 'sqlsrv';$db['default']['dbprefix'] = '';$db['default']['pconnect'] = TRUE;$db['default']['char_set'] = 'utf-8';

Just don't know how to call?

In the model call for example $db = $this->load->database (' Default ', TRUE);
$db->query ($sql);
The above configuration file is wrong, two different databases need to be separated, cannot use the same key name default, otherwise the subsequent configuration will overwrite the previous configuration. The code above is to choose a different database configuration based on the key name.

$db1=$this->load->database('default',TRUE);$db2=$this->load->database('another',TRUE);

No longer available when multiple databases are called$this->db->query($sql);
can only be used$db1->query($sql);

By default, you can use it directly using the $this->db.

For the second, you need to change the name of the default to identify their configuration, so you can use the
$db 2= $this->load->database (' another ', TRUE);
To invoke

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.