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

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;

Related

Remote database connection in codeigniter

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.

Connect with remote mySql from localhost with codeigniter

I have a remote mysql server. Now I am developing a software in Codeigniter integrated with that mysql server. I gave the GRANT ALL to 'user'#'myid' in mysql user. But codeigniter shows the following error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
How can i use remote mysql in my local development environment?
BTW: I use WAMP in windown 7.
Thanks in advance.
EDIT:
Database Configuration:
$db['default']['hostname'] = '198.xxx.xx.66';
$db['default']['username'] = 'root';
$db['default']['password'] = 'xxxxxx';
$db['default']['database'] = 'm000db';
$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;

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

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;

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