I am using CI and my database is on dream host. And when i connect database. it gives error like this
A Database Error Occurred
Unable to connect to your database server using the provided
settings.
Filename:
/home/demo_smartmobe/demos.smartmobe.com/nayacinema/webpart/third_party/MX/Loader.php
Line Number: 98
my ci code for database connection is
$db['default']['hostname'] = 'hostname';
$db['default']['username'] = 'username';
$db['default']['password'] = '******';
$db['default']['database'] = 'database_name';
$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;
username and password is correct.
and i had tried by simple php code and it works. Php Code is here.
$hostname = "mysql.demos.smartmobe.com"; // eg. mysql.yourdomain.com (unique)
$username = "nayacinema"; // the username specified when setting-up the database
$password = "****"; // the password specified when setting-up the database
$database = "nayacinema"; // the database name chosen when setting-up the database (unique)
$con=mysqli_connect($hostname,$username,$password,$database);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo 'done';
}
$result = mysqli_query($con,"SELECT * FROM TblUsers");
print_r($result);
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br>";
}
what may be the problem? I had add MX folder in Ci folder for make it HMVC. And error is shown in /third_party/MX/Loader.php. IN localhost in works but in live there is error .please help me. Thank u
You stated your username and password are correct, but what about the hostname?
Modify your hostname setting to be your correct hostname.
E.g.
$db['default']['hostname'] = 'localhost';
or
$db['default']['hostname'] = '127.0.0.1';
You will also need to change $db['default']['database_name'] to match the name of the database you're attempting to use.
You need to get the correct database connection info from Dreamhost. You can find the ones that you have set up for that domain in your Dreamhost Web Panel, under the MySQL Databases tab, on the left side. Under that page, you can find the hostname, database, and username. If you click on the username that has access to the database, you can find out what your password is. Put those values into your database.php config file, like in the fields show below.
$db['default']['hostname'] = 'mysql.example.com';
$db['default']['port'] = "3306";
$db['default']['username'] = 'mysql_username';
$db['default']['password'] = 'mysql_password';
$db['default']['database'] = 'mysql_database';
First of all, if you are accessing the database within the same pc.
(localhost and 127.0.0.1 are the same)
If not, the host name should be identified by DNS Name or with domain name included.
And if the database port is not the default (3306), you should include it on the config.
Like the code in your php:
$db['default']['hostname'] = 'mysql.demos.smartmobe.com';
$db['default']['username'] = 'nayacinema';
$db['default']['password'] = '******';
$db['default']['database'] = 'nayacinema';
$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;
//$db['default']['port'] = 3307; //modify if the port is not the default 3306
Related
I've been trying to connect to my database so I can make some changes in a website, in a local way, not directly on the server. But I always come to this error:
"Unable to select the specified database: backup"
. It says that the problem is in the file:
Filename: C:\xampp\htdocs\system\database\DB_driver.php
Line Number: 141.
But this is what I have in the line:
$this->display_error('db_unable_to_select', $this->database);
My script is like this:
$db['default']['username'] = 'teste';
$db['default']['password'] = '123456';
$db['default']['hostname'] = 'localhost';
$db['default']['database'] = 'backup';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'tbl_';
$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 changed the name of the driver, but it didn't work as well.
the line of code that try to select the db:
function db_select()
{
return #mysqli_select_db($this->database, $this->conn_id);
}
How to proceed?
I am using Postgresql database connection with codeigniter. I am new to postgresql. The site opens. But I cannot login nor fetch any values from the database.
I will upload the code for my config file as well as the database.php file.
config.php
// Keep as it is for same if MySQL server is running on same server
define("DBHOSTNAME",'ip_address');
// Add your database name here
define("DBNAME",'db_name'); // Here the database name is 'dummy_myecommerce'
// Add your database user name here
define("DBUSER",'username'); // Here the username is 'dummy_website'
// Add your database password here
define("DBPWD",'password');
Now I will upload the database.php file:
$db['default']['hostname'] = 'ip_address';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'db_name';
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = 'pre_';
$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;
$db['default']['port'] = 5432;
If anything else is required, please let me know. Thanks
Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might require a full DSN string to be provided. If that is the case, you should use the ‘dsn’ configuration setting, as if you’re using the driver’s underlying native PHP extension, like this:
// PDO
$db['default']['dsn'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
Helpful link - http://www.codeigniter.com/user_guide/database/configuration.html
Try this as well
$db['default']['hostname'] = 'pgsql:host=localhost;dbname=yourdb'; //set host
$db['default']['username'] = 'your username'; //set username
$db['default']['password'] = 'your password'; //set password
$db['default']['database'] = 'your database'; //set databse
$db['default']['dbdriver'] = 'pdo'; //set driver here
I'm developing a website application using codeigniter at localhost and then i host it in hawkhost.
At localhost it runs well, but at host there's and error :
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php Line Number: 346
this is my db configuration
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '****';
$db['default']['password'] = '****';
$db['default']['database'] = '****';
$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;
I know many people already asked this problem but it doesn't seems to solve anything on my case.
changing $db['default']['db_debug'] = TRUE; to false only hide the error but when i tried to get data from query it doesn't return anything.
I also tried to change $db['default']['pconnect'] = FALSE; to true and still doesn't work.
Any help please?
Just change localhost to the local ipaddress i.e. 127.0.0.1 and it will start working.
$db['default']['hostname'] = 'localhost';
to
$db['default']['hostname'] = '127.0.0.1';
In my case setting pconnect to false worked.
$db['default']['pconnect'] = FALSE;
The problem is really due to credentials.
I test it using simple code to check if connection can be made.
The problem is in username, i realize there's additional suffix when using hosting. such as suffix_user
I think the same errors in Core/Loader.php Line Number: 346 has the same solution. make sure the username, password and host are right.
It's solved. Thank you everyone for helping.
Just change
$db['default']['hostname'] = 'localhost';
to
$db['default']['hostname'] = '127.0.0.1';
and voila.
Most of the time this problem happens when codeigniter is in live environment.
That’s why I assumed a domain name ‘(example: domainname.com)’ and after creating a mysql database (example: testDb) and user name (example: testUser) you will find a prefix name automatically added with your mysql database name and user name like ‘domainname_ testDb’ and ‘domainname_ testUser’.
Now in codeigniter /application/config/database.php edit following:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$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;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'domainname_ testDb ';
$db['default']['password'] = '*******';
$db['default']['database'] = 'domainname_ testUser';
$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;
If anyone else is having this issue, try disabling SE-Linux if you have it enabled. It was causing the connection issues for me, with php 5.4.
Also worth checking is switching
$db['default']['dbdriver'] = 'mysql';
to
$db['default']['dbdriver'] = 'mysqli';
as mysql is depreciated after php 5.5.
My data is not inserted into the database on the production site, while it is working correct on my local testing site.
My configuration of codeigniter is correct.
If I manually execute the query in the database, it shows the correct message and the data get's inserted into the database.*) When I print the query, it is as expected too.
I think it is a server configuration issue. I am using go daddy and mysql.
Database configuration:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'etc';
$db['default']['password'] = 'etc';
$db['default']['database'] = 'ieshopif_y';
$db['default']['dbdriver'] = 'mysql';
$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;
*) After manually executing the query, I get this success message:
Connecting to database: ieshopif_y
Connected OK:file: /home/ieshopif/public_html/application/config/database.php Line: 82
I'd like to know how I have to configure the database to make it work, if it is a database issue.
These options could be different in production, development and testing:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'etc';
$db['default']['password'] = 'etc';
$db['default']['database'] = 'ieshopif_y';
I suggest you separate this with an ENVIRONMENT constant defined on index.php, because the hostname could be different in production server. Try this:
if (defined('ENVIRONMENT')) {
switch (ENVIRONMENT) {
case 'development':
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'ieshopif_y';
break;
case 'testing':
case 'production':
$db['default']['hostname'] = 'domain.com';
$db['default']['username'] = 'root';
$db['default']['password'] = 'secure_pass';
$db['default']['database'] = 'ieshopif_y';
break;
default:
exit('The application environment is not set correctly.');
}
}
I am using CodeIgniter and I am trying to access a database that is placed remotely on another server. I can access that server remotely but I can't connect via my MySQL Connection settings. Here are my MySQL settings:
$db['default']['hostname'] = 'myhostname';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'MyDb';
$db['default']['dbdriver'] = 'mysqli';
$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 not sure where I am making a mistake so if someone can point out the mistake it will be really helpful.
First, check username and password for mysql (obviously username cannot be root and password cannot be blank for security reasons) and for hostname, you might have to supply IP address of your server where mysql is hosted. Rest configurations appear to be fine. You can ask for these information from your hosting company.