[Company Logo Image] 

Home Up Contents Coffee Break Credits Glossary Links Search

 
How to Query a SQL Server Database from PHP

 

 

Home
Analysis Services
Azure
CLR Integration
High Availability
Open Source
Security
SQL Server 2008
SQL Server 2012
SQL Server 2014
SQL Server 2016
SQL Server 2017
SQL Server 2019
Tips
Troubleshooting
Tuning

How to Query a SQL Server Database from PHP.


Applies to: SQL Server 2012 Express on Windows Server 2012 Standard Edition, Microsoft Drivers 3.0 for PHP v5.4 for SQL Server in IIS, Microsoft Drivers 3.0 for PHP v5.4 for SQL Server in IIS, Microsoft Web Platform Installer 4.6, IIS 8.
 

This article shows how to connect to a SQL Server database and run query from a PHP program.

To be able to run our PHP program you need to perform the following steps:

1. You may not have to do this, but I created a Hyper-V virtual machine with 1.5 GB of RAM, and installed Windows Server 2012 Standard Edition.

2. Change the Windows Server computer name to a more familiar name that the default WIN-XXXXXXXXXXX. I changed the computer name MORILLOPHP.

3. Install the Web Server (IIS) role on Windows Server 2012 with all default features it requires. You can test the Web server by running the following command (Windows Logo + R): http://localhost. The IIS 8 logo should appear on Internet Explorer.

4. Download and install Microsoft Web Platform Installer 4.6 from here. Install "Microsoft Drivers 3.0 for PHP v5.4 for SQL Server in IIS" and "PHP 5.4.24" using Microsoft Web Platform Installer 4.6.

5. To test the PHP installation, save the following PHP code on the C:\inetpub\wwwroot directory and name the text file as phpinfo.php. Then run the program using Internet Explorer like this: http://localhost/phpinfo.php.

<?PHP

phpinfo();

?>

6. Install SQL Server Express 2012 with Tools using this article.

 

Creating a simple table using SQL Server Management Studio.
 

I created a simple table using SQL Server Management Studio (SSMS) and populated the table with one record. These are the steps I followed:

Open SSMS. Make a right click on Databases folder, select "New database", and provide a database name and click OK. I named the database "MorilloDB".

Now, let's create a new table by expanding the MorilloDB database folder, make a right click on the tables folder, and select "New table..." and type the column names shown below.




Make a click on the Save button and name the table "Employees".






Make a right click on the Tables folder, and select "Refresh" to make the newly created table show in Object Explorer.







Now let's create some records on the Employees table by making a right click on the table, and then select "Edit Top 200 Rows".




 

I created just one record, but you can go ahead and add some more.



 


Creating the PHP program to query the database.


Let's create the PHP program to query the table we just created above in SQL Server. Type the following program in Notepad or Notepad++ and name the program BasicProgramQuerySQLServer_1.php and store it on the C:\inetpub\wwwroot folder.










Then run the program using Internet Explorer as shown below.





 

 

 

.Send mail to webmaster@sqlcoffee.com with questions or comments about this web site.

哆哆女性网远字起名前十名制作网站的模板拜托了老师常州网站制作报价新乡公司网站设计北美最新电影排行榜孩子起名字,姓马的名字专属个性签名手机饰品起名可爱网名格式挪威的森林剧情介绍出生年月日起名免费周公解梦葡萄树重庆网站设计企业8月8号梦幻家园最新破解广州继续教育网好听的童装店铺起名的芦笋的种植恐龙并没有灭绝网站营销与推广的书手机网站建设平台的国考成绩和排名一起出吗小教室夜雨何时听萧瑟seo优化 知乎罗姓的宝宝起名火凤凰电视剧网页制作公司企业网站起点玄幻小说排行榜完本前十名淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化