Remote database connection in codeigniter - php

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.

Related

CodeIgniter 2.2.1 and Xampp 5.5.19 Not Connecting to Database

I was previously using Xampp 1.8.2 and CodeIgniter 2.2.1 connecting to MSSQL 2012. My database configuration was working well and fine until i moved to xampp 5.5.19 and using the same database configuration. This is how i did it:
I downloaded respective Microsoft drivers for PHP for SQL server (php_sqlsrv_5ts.dll) and copied it to the ext folder in the php installation folder. I then updated my php.ini file to load this extension. I also configured my MSSQL co listen to a specific port (is used the standard 1433). I then configured my database connection in the config codeigniter folder as follows:
$db['default']['hostname'] = 'CORE14\CORE12';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'sa';
$db['default']['port'] = 1433;
$db['default']['database'] = 'HomoOpes';
$db['default']['dbdriver'] = 'sqlsrv';
$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 restarted my server and tried to access my application. I get the error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\TUMHRMS\system\database\DB_driver.php
Line Number: 124
I thought xampp 5.6 was unstable and i uninstalled it because it was bringing the same problem it then installed xamp 5.5.19 and am getting the same problem. Somebody help.
Thank you
try to use odbc driver
$db['mssql']['hostname'] = 'Driver={SQL Server};Server=CORE14\CORE12;Database=HomoOpes';
$db['mssql']['username'] = 'sa';
$db['mssql']['password'] = 'sa';
$db['mssql']['database'] = 'HomoOpes';
$db['mssql']['dbdriver'] = 'odbc';
try to change
$db['default']['dbdriver'] = 'sqlsrv';
to
$db['default']['dbdriver'] = 'mysql';
or
$db['default']['dbdriver'] = 'mysqli';

Connect to an SQL 2008 server in PHP (Windows/Linux)

For our project we need to connect to an SQL server in PHP Codeigniter. Our server runs on an Linux webserver with Centos.
Normally we are common to use MYSQL to connect. For this project an SQL 2008 server already exist.
Is it possible to connect to an SQL 2008 server on such a Linux machine? And what do i need for that? Is it also possible to test the connecttion first in my Xampp dev in the local network?
I've had the greatest success with SQL Server connections running through ODBC drivers above anything else. Have you tried that yet?
http://technet.microsoft.com/en-us/library/hh568454.aspx
Try-> in your application/config/database.php put the following:
// This address is valid if you're on the same domain as the server:
// If not, you can put the ip address or url here as well.
$db['default']['hostname'] = 'DBComputerName\SQLEXPRESS';
// if you need a non default port uncomment and edit
//$db['default']['port'] = '5432';
$db['default']['username'] = 'databaseUsername';
$db['default']['password'] = 'databaseenter code herePassword';
$db['default']['database'] = 'DatabaseName';
$db['default']['dbdriver'] = 'sqlsrv';
$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;

Connection to remote mysql from localhost

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;

XAMPP codeigniter Database Error

I face an error when trying the tutorial of CodeIgniter. When I try the "News section". I get the error
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\CI\system\database\DB_driver.php
Line Number: 124
I am using XAMPP and my os is windows7(64 bit).
My details in the C:\xampp\htdocs\CI\application\config\database.php are follows
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'xxx';
$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 succeeded When to establish the connection to db with core php.
Somebody help me to resolve this..
Thanks in advance..
Reset XAMPP and check if phpmyadmin working and database 'xxx' exist.
using phpmyadmin create the database..name it xxx
then try loading the site again
Also check the index.php file in the root folder.
Sometimes people will place code here to change which database file it uses based on the domain.. not sure what codeigniter tutorial you are following.
first make sure you load your database library
$autoload['libraries'] = array('database');
then check your default settings to see whether something is missing using.
echo '<pre>';
print_r($db['default']);
echo '</pre>';
Set db_debug to false in your CI's database.php.
Another tip. When locally everything is very very slow, change localhost to 127.0.0.1.
Kamikaze™ - 08 December 2011 06:39 AM
Is your table name in uppercase? Be careful with lowercase and uppercase, I had the same problem.
Try this: $this->db->get(“PROJECT_USERS”);

codeigniter - cannot connect to MySQL database

Error that is getting printed out
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I have been looking through all the other questions and nothing seems to work. Still getting this error. All the info in my database.php file matched up to my info on the mysql server that I am running on the command line. I am also using mysqld and mysql.server start. I have tested the connection on the command line with
mysql -h localhost -uroot -p dbname
And that seems to work on my command line, but it is giving me the error above when I am referencing it on a localhost server I have set up with the codeigniter project. What am i doing wrong? I have double and triple checked naming conventions to make sure that it isn't the issue.
Also, I am on OS X Mavericks
my code in the config file is as follows:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'PASS';
$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;
I have run into this problem frequently myself with CodeIgniter. The usual solution (for me!) is to set 'pconnect' and 'db_debug' to FALSE:
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
I tried to change the following line in my config/database.php file and it worked. (The error your getting means something is wrong with your config/database.php)
'hostname' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Explanation for this behaviour is written here (MySQL on OSX finds mysql.sock wrongly).
Cheers!

Categories