trusted connection to sql server 2008 from php

Posted on 2011-04-27
Last Modified: 2012-05-11
below is the code for sql authenticaion connection string

how about for trusted connection to sql server
	$myServer = "localhost";

	$myUser = "sa";
	$myPass = "#$";
	$myDB = "db01";

	//connection to the database
	$dbhandle = mssql_connect($myServer, $myUser, $myPass)
	  or die("Couldn't connect to SQL Server on $myServer");

Open in new window

Question by:doramail05
    LVL 9

    Accepted Solution

    Here is the msdn link discribes how you can do this

    code is something like this

    $serverName = "(local)";
    $connectionInfo = array( "Database"=>"AdventureWorks");

    /* Connect using Windows Authentication. */
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
         echo "Unable to connect.</br>";
         die( print_r( sqlsrv_errors(), true));

    LVL 15

    Expert Comment


    if you want to use Windows Authentication with PHP, its good to know some important stuff  about it
    LVL 7

    Expert Comment

    by:Vimal DM

    just search for the below one's online,you will find the easy way of doing this

    1) $conn = odbc_connect('myDSN','','');

    2) $query = "select * from cars";
      //perform the query
      $result=odbc_exec($conn, $query);

    3) $colName = odbc_num_fields($result);

    Just look for this link,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now