In this video I will connect mssql database in php 7.3 and insert data in mssql database and on another function i will fetch that data in php and present on screen.
Steps to create and setup connection between php and mssql.
First you need to create a database in MSSQL.
Here I created a database called "ci_mssql"
after creating database I created a table of users where I made 3 column.
first is id (Auto Generated)
second is fname - nvarchar(50) datatype
third is lname - nvarchar(50) datatype
as per the screen you can see, users table is blank.
no i download CI from website.
I already downloaded CI-3 from website and extract in wamp/www folder.
on the screen you can see, welcome screen of my new CI-3 project.
welcome controller and welcome view is default in CI-3.
Now I need to connect MSSQL database in php
for that I need to add some dll in my wamp server. let me show which dll I need to place in wamp folder.
left side of the screen showing 2 dll which is highlighted.
DLL name -
php_sqlsrv_73_ts.dll
php_pdo_sqlsrv_73_ts.dll
after download above 2 dlls, you need to place those dll in wamp folder path
"wamp64\bin\php\php7.3.21\ext"
above 2 dlls working only with php 7.3.* version, so if you are using any other php version find similiar dll but for your php version and place them in correct php version folder.
after placing/copy those dll files in php ext folder.
you need to go "wamp64\bin\apache\apache2.4.46\bin" and open php.ini file in editable mode.
As I opened php.ini file in notepad++.
add below mentioned "extension" in php.ini as on left side of screen i am showing
extension=php_pdo_sqlsrv_73_ts
extension=php_sqlsrv_73_ts
after adding those two extensions all settings done for wamp64. now you just need to restart your wamp64 server.
After restarting wamp server. go to your browser and check your project is running default controller and view.
As I am running default controller in browser you can see default view on browser.
now its time to write some code in CI to connect MSSQL database.
now open your controller where you want to connect database and save and get data from mssql.
I recommend to make a helper where you can write a code for database connection setup.
In my case I made a "database_helper.php" file in my project and write a connection code in that helper file.
In this you need to write code as showing in left side of the screen.
after writing connection code. go to your controller.
my controller name is - welcome.php
I made 2 functions
first is for inserting data in mssql
second is for fetching data from mssql.
in insertMSSQL function I called helper function for connection open of mssql database.
after open I made a if condition for checking $conn is successfully connected or not.
once $conn connected. I wrote a query of insert in table and execute query and after execution of query i wrote for connection close.
I just show in screen before executing database table values are blank and after insert function run, insert successfully in mssql.
let me truncate table and show you once again.
After insert its successfully saving data in mssql database.
now I wrote a code for fetching data from mssql.
in controller I made a function selectMSSQL
in that same I open mssql connection and executing select query and printing data of mssql.
on left side of screen you can see, we inserted 2 rows in mssql and both results printing in php CI.
above .dll files I will attach and link will add in description as well as I will upload project and share link in description.
download files-
MSSQL Database - https://www.dropbox.com/s/jx6ykhrzfui...
Project Files - https://www.dropbox.com/s/uh0tg3s7p09...
DLL Files -
https://www.dropbox.com/s/ydude50sdzs...
https://www.dropbox.com/s/grvcc7uifou...
Thank for watching,
please subscribe :)
PC Specification -
Processor - Intel i5 9400F
Motherboard - MSI Z370 A Pro
RAM - Corsair 16GB
GPU - Zotac RTX 2060 6GB
SMPS - Cooler Master 750 80+
-------------------------------------------------------------------------------------------------------------
DISCLAIMER: This Channel Does Not Promotes Any illegal content ,
all contents provided by This Channel is meant for EDUCATIONAL purpose only .
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research.
Fair use is a use permitted by copyright statute that might otherwise be infringing.
Non-profit, educational or personal use tips the balance in favor of fair use.
-------------------------------------------------------------------------------------------------------------
#gouravguptaofficial #gouravgofficial #LearnWithGouravGupta #LearnWithGouravG