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
}
Related
I have 2 server A (Code) and B (Database). I need to access (connect) A to B. I am using mysql 5.6 phpmyadmin and php running in ubuntu 14.04. All I know is that i need to whitelist a user in phpmyadmin. Since I am new to this, can anyone guide me on this.. I have made changes in database.php in server A as follow
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'IP of Server B';
$db['default']['username'] = 'abc';
$db['default']['password'] = '123';
$db['default']['database'] = 'db1';
$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;
After doing this change when i run the my server A the following error pops up
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
I have even edited /etc/mysql/my.cnf in server B by binding the server's IP.
bind_ip=[Server B IP]
I can not comment so I'll just add it here, first of all, make sure you can access your database server remotely. Under normal circumstances port 3306 will be blocked.
Once all the proper credentials are given in database.php, we need to comment out bind-address=1270.0.1 in /etc/mysql/my.cnf file of Server B. Before that stop mysql and restart it once the editing is done.
I have searched the net to no solution for a problem I am facing.
I am working on a codeigniter project which I am running on a localhost Apache Server. For the database, I am attempting to connect from CI's database.php configuration file to connect to a remote server.
The following is my configuration
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'remotedatabase.com';
$db['default']['username'] = 'remote_2102Dev';
$db['default']['password'] = '1q2w3e4r5t';
$db['default']['database'] = 'remote_cs2102';
$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 have tried to connect to the remote Database via mysql workbench 5.5. So that means I have did the configuration correctly at the server side.
Please help me. Is this CI problem or there is something wrong with my settings. Thank you.
Check host entry # remotedatabase.com. It should be % in host
If your PHP version is >= 5.3 set db_debug to false:
$db['default']['db_debug'] = FALSE;
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
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.