I've seen a lot of posts but none that actually worked. Can someone provide a clean/clear way to connect Codeigniter with a MS SQL Server on a Mac? This is high level but I have yet to see a solution that clearly demonstrates this. Thanks a bunch!
I have already done this, in your application/config/database.php put the following:
// This address is valid if you're on the same domain as the server:
// If not, you can put the ip address or url here as well.
$db['default']['hostname'] = 'DBComputerName\SQLEXPRESS';
// if you need a non default port uncomment and edit
//$db['default']['port'] = '5432';
$db['default']['username'] = 'databaseUsername';
$db['default']['password'] = 'databasePassword';
$db['default']['database'] = 'DatabaseName';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;
I know how frustrating this was, as a word of caution, not all Active Record functions work or work as expected, this is due to many SQL server quirks.
I recommend switching most of your Active Record queries to: $this->db->query();
PS If I remember correctly, MSSQL doesn't have a username preconfigured, you need to create a username and allow db access from outside of the subnet.
Refer to this in order to create the db user:
http://technet.microsoft.com/en-us/library/aa337545.aspx
and allow access:
http://support.webecs.com/KB/a868/how-do-i-configure-sql-server-express-to-allow-remote.aspx
I use the PDO driver... this works for me:
$db['mssql']['hostname'] = 'sqlsrv:server=myserverIP;database=mydb;encrypt=true;trustservercertificate=true';
$db['mssql']['username'] = 'myun';
$db['mssql']['password'] = 'mypw';
$db['mssql']['database'] = 'mydb';
$db['mssql']['dbdriver'] = 'pdo';
$db['mssql']['dbprefix'] = '';
$db['mssql']['pconnect'] = TRUE;
$db['mssql']['db_debug'] = TRUE;
$db['mssql']['cache_on'] = FALSE;
$db['mssql']['cachedir'] = '';
$db['mssql']['char_set'] = 'utf8';
$db['mssql']['dbcollat'] = 'utf8_general_ci';
$db['mssql']['swap_pre'] = '';
$db['mssql']['autoinit'] = TRUE;
$db['mssql']['stricton'] = FALSE;
Related
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: /home/rehmantr/public_html/third_party/MX/Loader.php
Line Number: 94
Dear Sir,
I am facing this issue, my database.php file setting is below
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'hostname';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$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;
but still I am facing this issue,please help me.
I am using HMVC pattern of CI
I think its a problem with your credentials, verify that user and password are correct and that the user has access to the database you specify in the settings.
I have been working on a cms based website. But now that its time to upload it shows a database error
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I have checked my database.php file located in applications/config
Its contents:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'xy.in';
$db['default']['username'] = 'xy_eta';
$db['default']['password'] = '';
$db['default']['database'] = 'xy_livefiesta';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$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;
I am sure about the database name and the username
BUt not sure about the hostname(thts the same as the first domain that i purchased while buying a shared hosting)
Please help me out in finding the error
Web services do not allow you to have databases without a strong password.
You need to login with the administrator privilidge and set a password for the database and also set the password in the config/database.php file too.
Are you sure your hostname is correct? Try changing it to localhost
I have a functionality as follows:
When Any user logs in I want to connect to a particular DB based on login credentials
.
I tried with
$this->db->close();
and this->db->reconnect();
but it did not help
In your application/config/database.php you can define more than one database connection by doing
$db['database1']['hostname'] = 'localhost';
$db['database1']['username'] = 'db1_root';
$db['database1']['password'] = 'xxxxxx';
$db['database1']['database'] = 'database1_name';
$db['database1']['db_debug'] = false; //Important
$db['database2']['hostname'] = 'localhost';
$db['database2']['username'] = 'db2_root';
$db['database2']['password'] = 'xxxxxx';
$db['database2']['database'] = 'database2_name';
$db['database2']['db_debug'] = false; //Important
Then you can load specific databases by doing
$database1 = $this->load->database('database1', true);
$database2 = $this->load->database('database2', true);
Then rather than doing
$this->db->query();
You will need to do either
$database1->query();
$database2->query();
You can connect using a dynamic config in your controller/model/library/whatever by passing a config array to $this->load->database().
$config['hostname'] = "localhost";
$config['username'] = $user_name;
$config['password'] = $user_password;
$config['database'] = $user_database;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$user_db = $this->load->database($config, true);
I figured out my answer.. Coded as follows:
in the database.php file i have added a new database config:
$db['db2']=$db['default'];
$db['db2']['database'] = 'new_db2';
and then in all the models constructor function i have put the following code:
$new_db = $this->load->database('db2', TRUE );
$this->db = $new_db;
So in this case i don't need to change all my queries. Hurray!!! :)
I am trying to upload my codeigniter website to cpanel
But, I am getting following error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I have uploaded all my files in directory:
/home/mycpanelusername/public_html/
And,
database name = mycpanelusername_db_databasename
databae username = mycpanelusername_fajs
database password = mydbpassword
and I granted all privileges to my database
My database.php file is like this:
$db['default']['hostname'] = 'http://myurl.org';
$db['default']['username'] = 'mycpanelusername_fajs';
$db['default']['password'] = 'mydbpassword';
$db['default']['database'] = 'mycpanelusername_db_databasename';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$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;
Thank you, If it's not clear please ask me
give $db['default']['hostname'] as ip address
$db['default']['hostname'] ="254.000.0.0";
or
$db['default']['hostname'] = 'localhost';
try like this
Try with localhost like
$db['default']['hostname'] = 'localhost';
May it works and also once check the login credntionals and Db name
I have been at this one all night and our offices open in 69 minutes.
Our server was just updated to PHP 5.3.13 and a critical online application that connects to MS SQL 2008 is just producing a blank page - no errors being logged, just snow. It is written in CodeIgniter 2.1.2.
If I do not autoload ( or try to connect to the db ), the page displays the static elements. Once I add the database.php config file, it's a white-out.
I am trying the mssql and the sqldrv drivers and getting the same results.
I am hoping to find some ideas on how I can go about debugging this solution in an ASAP sort-of-way.
My offending config (which worked until the upgrade) in the database.php looks like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "<<SQL SRV NAME>>";
$db['default']['username'] = "<<USERNAME>>";
$db['default']['password'] = "<<PASSWORD>>";
$db['default']['database'] = "<<DATABASE NAME>>";
$db['default']['dbdriver'] = "mssql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
ANY thoughts are GREATLY appreciated.
A bit late now I suspect, but the current version of CodeIgniter (2.1.2) has the following in its Database config file by default:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database';
$db['default']['dbdriver'] = 'mssql';
$db['default']['dbprefix'] = '';
$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;
Note the extra couple of configs there at the end. It may be looking for them but as they're not supplied it's erroring...