Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:47:10+00:00 2026-06-17T11:47:10+00:00

My environment: – Windows Server 2008 R2. – Apache Webserver. – PHP 5.4.7 I’ve

  • 0

My environment:
– Windows Server 2008 R2.
– Apache Webserver.
– PHP 5.4.7

I’ve just downloaded and installed Microsoft Drivers 3.0 for PHP for SQL Server.
I’ve included “php_pdo_sqlsrv_54_ts.dll” into php.

Microsoft has included a helpful chm file with the drivers (SQLSRV_Help.chm).

In this help file there is a PDO example using windows authentication:

/* Connect using Windows Authentication. */
try {
  $conn = new PDO("sqlsrv:server=$serverName ; Database=AdventureWorks", "", "");
  $conn->setAttribute( PDO::ATTR ERRMOE, PDO::ERRMODE EXCEPTION );
}

But I have to connect to our MS SQL Server 2008 R2 using SQL Server Authentication!

What is the difference is between connecting to SQL Server

  1. using PDO and Windows Authentication
  2. using PDO and SQL Server Authentication

Is it just the connect string? Do I have to write:

$conn = new PDO("sqlsrv:server=$serverName; Database=AdventureWorks; UID=sa; PWD=abc");

or do I have to write:

$conn = new PDO("sqlsrv:server=$serverName; Database=AdventureWorks; User Id=sa; password=abc");

Thanks in advance

Update:

I found a resoure:

http://www.connectionstrings.com/sql-server-2008

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:47:12+00:00Added an answer on June 17, 2026 at 11:47 am

    There are optional second and third parameter in the constructor which specify the username and password as described here:

    PDO::__construct

    Creates a connection to a SQL Server database.

    Syntax PDO::__construct($dsn [,$username [,$password
    [,$driver_options ]]] )

    Parameters

    $dsn: A string that contains the prefix name (always sqlsrv), a colon,
    and the Server keyword. For example “sqlsrv:server=(local)”. You can
    optionally specify other connection keywords. See Connection Options
    for a description of the Server keyword and the other connection
    keywords. The entire $dsn is in quotation marks, so each connection
    keyword should not be individually quoted.

    $username: Optional. A string that contains the user’s name. To
    connect using SQL Server Authentication, specify the login ID. To
    connect using Windows Authentication, specify “”.

    $password: Optional. A string that contains the user’s password. To
    connect using SQL Server Authentication, specify the password. To
    connect using Windows Authentication, specify “”.

    […]

    This implies that you can connect to SQL Server using PDO + SQL authentication like this:

    $conn = new PDO(
        "sqlsrv:server=$serverName ; Database=AdventureWorks",
        "sa",
        "strong password"
    );
    

    The connection options section also mentions that you cannot use UID and PWD parameters in connection strings when using PDO_SQLSRV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

environment: microsoft sql server 2005, 2008 given: IF object_id('tempdb..#MyTempTable') IS NOT NULL BEGIN DROP
Environment: Windows, SQL Server 2008 For example, my database has Table1, Table2, Table3... TableN,
Environment: Windows Server 2008 R2 on Amazon EC2 Netbeans IDE with Glassfish started on
Environment: SQL Server 2005/2008, pubs database I have inserted into a table variable a
Environment: Windows/7 + Apache/2.2.21 + PHP/5.3.8 File contents of test.php : hello, <?=$test?> File
Environment: Windows Server 2003 R2 Enterprise 64bit, SP2 .NET framework is supposedly installed (2.0
environment: client windows 7 ultimate x64 TortoiseSVN(lastest) server ubuntu 10.4 svn (it installed by
Environment info: *Windows Vista *PHP 5.2.9-2 I'm working on a project. Let's say it's
Environment: Windows XP, SpringSource Tool Suite 2.3.2, Roo 1.0.2.Release, Java 1.6.0_10, tc Server 6.0
Environment: SQL Server 2005 I have a stored proc which receives comma separated value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.