I have a Codeigniter project on a machine and it runs as public access. However the MySql database it uses is accessible only through localhost. When I run the application, I get
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I follwed the instructions mentioned here but I am still getting the same error
Try
1. print_r($params) and print_r($active_record);
2. if the $params are still correct then simplify $active_record
3. echo mysql_error();
4. $db[‘default’][‘db_debug’] = true/false
5. $db[‘default’][‘stricton’] = true/false;
[edited]
I have set the parameters as
$db['default']['hostname'] = 'mysql12.freehostia.com';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'myDB';
$db['default']['dbdriver'] = 'mysql';
$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;
Related
I'm having a problem in codeigniter message "Unable to select the specified database Filename: E:\xampp\htdocs\marketingtools\system\database\DB_driver.php"
My database is existing and the credentials are correct because most of the time the program runs properly and then suddenly the error occur I don't know what is happening because i did not change anything in xampp settings and codeigniter settings but the error happens and ill wait for a while the program runs properly again.
here is the sample of my code
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root'; //aims_prog
$db['default']['password'] = ''; //yqUMaEBrvM8j6emD
$db['default']['database'] = 'marketingtools';
$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;
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
This is working fine in local. But in live server i am getting an error like above. Please help me to resolve this issue
Here is my database.php
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'dbname';
$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;
hi just put this code in database.php and change username,database,password.
$active_group = 'default';
$query_builder = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'xyz';
$db['default']['password'] = 'Z~5gvyigui7bujbc';
$db['default']['database'] = 'demo';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$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;
sometime this error display when credentials are wrong make sure the username, password and host are right.
I am using codeigniter 3.0 and I am trying to connect to a remote data base. I can successfully connect from my personal pc using a remote mysql user. However when I put the site in production mode on my linux cpanel hosting it cannot connect. Are there any known issues with this type of connection versus a local one?
My webhost is linux (cpanel) and my database is mysql and lives on a windows vps.
Here's my connection info:
$db['default']['username'] = "root";
$db['default']['password'] = "mysql";
$db['default']['database'] = "cms";
$db['default']['hostname'] = "localhost";
$db['default']['dbdriver'] = "mysqli";
$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";
/**
*
* THIS IS YOUR GAME DATABASE CONENCTION INFO
*
**/
$db['conquer']['username'] = "root";
$db['conquer']['password'] = "mysql";
$db['conquer']['database'] = "cq";
$db['conquer']['hostname'] = "104.238.133.31:3306";
$db['conquer']['dbdriver'] = "mysqli";
$db['conquer']['dbprefix'] = "";
$db['conquer']['pconnect'] = FALSE;
$db['conquer']['db_debug'] = TRUE;
$db['conquer']['cache_on'] = FALSE;
$db['conquer']['cachedir'] = "";
$db['conquer']['char_set'] = "utf8";
$db['conquer']['dbcollat'] = "utf8_general_ci";
$active_group = "default";
$active_record = TRUE;
This works perfect in development I am using an IP for the host name and my mysql user on the vps has remote connections enabled.
In linux base server it use localhost for host name. but in windows server there is an ip address
$db['default']['hostname'] = '';//change ip to here
$db['default']['username'] = '';//input relevant username
$db['default']['password'] = '';//input relevant PW
$db['default']['dbdriver'] = '';//input relevant Driver
I have a problem in connecting database in Codeigniter , cause my database name is "database-db_sample", so I'm wondering if the -(hypen) in my db name is the reason why I got an error,
This is the error i got
A Database Error Occurred
Unable to select the specified database: database-db_sample
Can someone tell me what's I had done wrong,
This is my db config
$db['online']['hostname'] = "localhost";
$db['online']['username'] = "root";
$db['online']['password'] = "";
$db['online']['database'] = "database-db_sample";
$db['online']['dbdriver'] = "mysql";
$db['online']['dbprefix'] = "";
$db['online']['pconnect'] = TRUE;
$db['online']['db_debug'] = TRUE;
$db['online']['cache_on'] = FALSE;
$db['online']['cachedir'] = "";
$db['online']['char_set'] = "utf8";
$db['online']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Your problem is either you don't have proper permissions set to root or mySQL doesn't like your use of hyphens.
So if you want to start new from phpMyAdmin. Start by going to your localhost->phpMyAdmin->privileges tab->add new user. Type in a username and use localhost then check the box for "create a database with same name...". That's it! Just don't use hyphens. Your database will have the same name as your username with all proper permissions.
I want Codeigntier to connect to a MySQL database on another server (not localhost). How do I configure this in the config/database.php file?
I set the hostname to the ip address with the proper username/password but it's not working.
The error I get says:
A Database Error Occurred: Unable to connect to your database server using the provided settings.
Heru, it seems like you simply want to change the current DB configuration from localhost to your live server. Do this, open up your database.php file in the application/config folder. Then find these lines.
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = ''; // might be empty or might be full
$db['default']['database'] = 'your_database';
and change it to this . . .
$db['default']['hostname'] = 'your_host_name';
$db['default']['username'] = 'your_user_name';
$db['default']['password'] = 'your_password';
$db['default']['database'] = 'your_new_database';
depending if your on a shared host or not and other factors. Your host may provide you with a new host name , may require a password and may provide you with a pre-configured database name. Look into the host provider for these pieces of information.
if that doesn't work . . .
You could also try to change it to this which finds your servers IP and converts it to a named address, but your database may or may not be sitting on a different address. But it's worth a shot.
$hostIP = $_SERVER['SERVER_ADDR'];
(string)$hostname = gethostbyaddr($hostIP);
$db['default']['hostname'] = $hostname;
$db['default']['username'] = 'your_user_name';
$db['default']['password'] = 'your_password';
$db['default']['database'] = 'your_new_database';
also if your confident of your database IP, change the above
(string)$hostname = gethostbyaddr($hostIP)
to
(string)$hostname = gethostbyaddr('10.11.12.123'); // with your IP #
This strikes me as a database permissions issue, not a CI issue. You're probably not authorized to connect from your IP. What happens when you run this on some random PHP page:
mysql_connect($server, $un, $pw) or die( mysql_error());
To fix this, simply run:
GRANT SELECT, DELETE, UPATE, INSERT ON $dbname.% TO $un#% IDENTIFIED BY ('$pw')
Triq,
You can add another set of database config to your config/database.php file (on top of your default set) like the following (you can change dbwrite to other name that you like):
$db['dbwrite']['hostname'] = "[other db host]";
$db['dbwrite']['username'] = "[other db username]";
$db['dbwrite']['password'] = "[other db password]";
$db['dbwrite']['database'] = "[other db name]";
$db['dbwrite']['dbdriver'] = "mysql";
$db['dbwrite']['dbprefix'] = "";
$db['dbwrite']['pconnect'] = FALSE;
$db['dbwrite']['db_debug'] = FALSE;
$db['dbwrite']['cache_on'] = FALSE;
$db['dbwrite']['cachedir'] = "";
$db['dbwrite']['char_set'] = "utf8";
$db['dbwrite']['dbcollat'] = "utf8_general_ci";
Then, you can pull this db reference using the following code:
$dbw = $this->load->database('dbwrite',TRUE);
$dbw->query(xxx); // this will execute the query on the other db
Make sure dbwrite is the same name that you are using on your other db config. $this refers to $CI instance.
You can easily Crated multiple database connection using codeigniter
$db['default']['hostname'] = "localhost:3306";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "buy599_erp";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRU`enter code here`E;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['magento6']['hostname'] = "localhost:3306";
$db['magento6']['username'] = "root";
$db['magento6']['password'] = "";
$db['magento6']['database'] = "magento6";
$db['magento6']['dbdriver'] = "mysql";
$db['magento6']['dbprefix'] = "";
$db['magento6']['pconnect'] = TRUE;
$db['magento6']['db_debug'] = TRUE;
$db['magento6']['cache_on'] = FALSE;
$db['magento6']['cachedir'] = "";
$db['magento6']['char_set'] = "utf8";
$db['magento6']['dbcollat'] = "utf8_general_ci";
$db['magento6stalkbuylove']['hostname'] = "localhost:3306";
$db['magento6stalkbuylove']['username'] = "root";
$db['magento6stalkbuylove']['password'] = "";
$db['magento6stalkbuylove']['database'] = "magento6stalkbuylove";
$db['magento6stalkbuylove']['dbdriver'] = "mysql";
$db['magento6stalkbuylove']['dbprefix'] = "";
$db['magento6stalkbuylove']['pconnect'] = TRUE;
$db['magento6stalkbuylove']['db_debug'] = TRUE;
$db['magento6stalkbuylove']['cache_on'] = FALSE;
$db['magento6stalkbuylove']['cachedir'] = "";
$db['magento6stalkbuylove']['char_set'] = "utf8";
$db['magento6stalkbuylove']['dbcollat'] = "utf8_general_ci";