Data is not inserted into database of production site - php

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.');
}
}

Related

code igniter error: Unable to connect to your database server using the provided settings. Filename: core/Loader.php Line Number: 346

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.

Cannot use MySQL in Pagoda box

This is my first time running Pagoda box. I have a PHP application. It needs to use a MySQL database. I have uploaded all the codes. I have also created a secure tunnel connection. but when I try to connect to the database, there is some problem. I am unable to load the database. It is not even giving me any error.
Here is my code
$this->load->database();
echo 'here';
$db['default']['hostname'] = 'tunnel.pagodabox.com:3306';
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = 'blog';
$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'] = 45000;
By the way, my MySQL database is running on port 3306 and tunnel is running in 45000.
Assuming that you are trying to connect to the mysql database in pagodabox from your local machine.
1.Secure Database Tunnel from Your Desktop. You might get something like this if the connection is successful.
Tunnel Established! Accepting connections on :
-----------------------------------------------
HOST : 127.0.0.1 (or localhost)
PORT : 3307
USER : (found in pagodabox dashboard)
PASS : (found in pagodabox dashboard)
2.Connecting from local codeigniter application to pagodabox mysql
$this->load->database();
echo 'here';
$db['default']['hostname'] = '127.0.0.1';
$db['default']['username'] = 'xxxx';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = 'blog';
..
..
$db['default']['port'] = 3307; // This one matches with Port displayed above.
</pre>
To see the error, open up index.php file and set error reporting E_ALL
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
error_reporting(E_ALL);
I would recommend a more portable configuration.
Pagodabox exposes the database credentials in the PHP $_SERVER variable and we can benefit like:
if (isset($_SERVER["DB1_HOST"])) {
// Pagodabox
$db['default']['hostname'] = $_SERVER["DB1_HOST"].':'.$_SERVER["DB1_PORT"];
$db['default']['username'] = $_SERVER["DB1_USER"];
$db['default']['password'] = $_SERVER["DB1_PASS"];
$db['default']['database'] = $_SERVER["DB1_NAME"];
$db['default']['port'] = $_SERVER["DB1_PORT"];
} else {
// my localhost configuration here
}

Database Error Occurred

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

CodeIgniter issue with database

I am following a beginner's tutorial for CodeIgniter, but I can't get the view to load correctly because I have a database connection error. I have followed everything step-by-step, and gone through it again several times, but not been able to fix it. Could someone please help me, or at least explain why this is happening?
Here is the database configuration I currently have setup:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'helloworld';
$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've also autoloaded the database library with the following code:
$autoload['libraries'] = array('database');
I would also like to point out that I am using PHP version 5.3.13. I not sure if the version of PHP would affect my code, so I added it anyway.
The exact error I'm getting is:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\CI\system\database\DB_driver.php
Line Number: 124
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root'; // default username if has not been set in phpmyadmin
$db['default']['password'] = ''; //leave it blank if has not been set in phpmyadmin
$db['default']['database'] = 'helloworld'; // this is your 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;
you might have tried to import the project to work space.Instead try to traverse to the project folder through project explorer

Codeigniter Multiple Database Connection

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.

Categories