Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> PHP >> Accessing SQL server database with PHP
Accessing SQL server database with PHP

The Microsoft SQL Server 2005 Driver for PHP allows PHP developers to access data in SQL Server databases. The driver includes support for Windows and SQL Server Authentication methods, transactions, parameter binding, streaming, metadata access, connection pooling, and error handling.
Views: 1264     Comments: 0
by Arun Singh on 3/12/2012

Accessing SQL server database with PHP

The Microsoft SQL Server 2005 Driver for PHP allows PHP developers to access data in SQL Server databases. The driver includes support for Windows and SQL Server Authentication methods, transactions, parameter binding, streaming, metadata access, connection pooling, and error handling.

To access the data from SQL server database you have to perform some changes in php.ini file.

Change 1: Put the extension file (php_sqlsrv.dll or php_sqlsrv_ts.dll) in the PHP extension directory. If you are running the non-thread-safe version of PHP (php5.dll), you should use the non-thread-safe version of the driver (php_sqlsrv.dll).

Change 2:  Uncomment the extension=php_sqlsrv.dll or php_pdo_mssql.dll in php.ini file.

After performing these changes restart your web server.

Example:

Here I’m creating an example for connecting PHP script with SQL server. In this example, simply I’m retrieving data from MS-SQL table and print it.

  

<?php

               // SQL server connection string information

                $serverName = "XXXX";

                $userName = "XXXX";

                $password = "XXXX";

                $db_Name = "MyDatabase";

                // connect with SQL server database

                $conn = mssql_connect($serverName, $userName, $password)

                        or die ("Database cannot connected successfully");

           // Select SQL database

                $selectDB = mssql_select_db($db_Name, $conn)

                            or die("Database cannot be opended");

                 // SQL server query

                $qry  = "select Name, ContactNo, EmailId from tblLogin";

                // Execute Query

                $qry_result = mssql_query($qry);

      // exatract table value

                while($row = mssql_fetch_array($qry_result))

                {

                    // print table value

                 echo $row['Name'].'\t\t';

                     echo $row['ContactNo'].'\t\t';

                     echo $row['EmailId'];

              }

                // Close connection with SQL server database

                mssql_close();

        ?>

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Arun SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2642
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.