. How to connect MSSQL DATABASE in PHP (Using with codeigniter) ~ Networking, Programming Blog, LOGISTICS JOBS

Wednesday, June 13, 2018

How to connect MSSQL DATABASE in PHP (Using with codeigniter)


on 7:48 AM


To connect MYSQL or MYSQLI in php is rather common than connetion SQL SERVER.  In my posted, i will using codeigniter for a example. For SQL SERVER in codeigniter, you need need to download some Drivers so that we can use SQL SERVER with other PHP .

The download version must be compatible to your PHP version example
Supported Operating System

  1. Version 4.0 supports PHP 7.0+ on Windows and Linux
  2. Version 3.2 supports PHP 5.6, 5.5, and 5.4 on Windows
  3. Version 3.1 supports PHP 5.5 and 5.4 on Windows
  4. Version 3.0 supports PHP 5.4 on Windows

link : https://www.microsoft.com/en-us/download/details.aspx?id=20098


Step 1. 

Download the Drivers from the below link
LINK : https://www.microsoft.com/en-in/download/details.aspx?id=20098
Extracted sqlsrv drivers and copy to folder ext in your php version


STEP 2.

Add these two line in your php.ini file
extension=php_pdo_sqlsrv_55_ts.dll
extension=php_sqlsrv_55_ts.dll 

STEP 3
RESTART Apache (Wamp)
The Above step will install the required drivers for the php to support SQL SERVER . Only the connection with php application is left. For that we need to change the configuration. In Codeigniter you need to edit the file config/database.php file with the correct credentials and fields like database, port username ,password...

$db['default']['hostname'] = 'IP Sql server';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'mssql';
$db['default']['database'] = 'YourDB';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['options'] = array(PDO::ATTR_TIMEOUT => 5);
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

After you changes in database.php, run you PHP apllication in the browser.

Done.

View on Youtube
  

0 comments:

Post a Comment