A Database Error Occurred in Codeigniter - mysql

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.

Related

PhpMyAdmin Configuration Storage => Multi-User / Server => still not working

my pma-installation is on one server(main-server).
On another server(client 1) i have the following:
my pma-database: phpmyadmin
my user with all privileges to that database: test_pma
my second user: mike
The user "mike" is just a normal mysql-user with one database and no privileges to the database "phpmyadmin".
My config.inc.php:
$i++;
$cfg['Servers'][$i]['verbose'] = 'Main Server';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/test/core/mysql.sock';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
/*Client Server 1...*/
$i++;
$cfg['Servers'][$i]['verbose'] = 'Client 1';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'IP-ADRESS'; // Just placeholder! In my config is the real IP!
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
// And then in a loop for every server...
...
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
...
The database exists and the tables too.
I tried to set the "controluser" with the following:
$cfg['Servers'][$i]['controluser'] = 'test_pma';
$cfg['Servers'][$i]['controlpass'] = 'test_pma';
and also with:
$cfg['Servers'][$i]['control_user'] = 'test_pma';
$cfg['Servers'][$i]['control_pass'] = 'test_pma';
but it is always the same problem.
If i log in to pma as the normal user "mike", i get the known warning about the configuration storage.
As the full privileged user "test_pma" all is fine.
Can someone tell me what is missing?
Damn what a jungle...
in my attempts i also cleared cookies and website-data, but with the same result.
Now i cleared cookies and website-data again and... it works!
The only difference:
First time deleting cookies and website-data, in my config.inc.php i used "control_user / control_pass".
But this time "controluser / controlpass".
Seems that in my attempts with "controluser / controlpass" i only logged out and logged in again, but not cleared cookies and website-data.
Why just logging in again wasn't enough? I don't know...
And regarding the "control_*" i thought it would be ok (according to the docs).
Maybe i misunderstood...

How to fix "Unable to select the specified database" in xampp and code igniter

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;

Refused connection to database in production but not local

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

using localhost MySql from online Codeigniter

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;

Can't connect to external database with Codeigntier

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";