Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can I use PHP PDO(PHP Data Objects) to connect to SQL Server 2008

Posted on 2008-10-21
9
Medium Priority
?
1,951 Views
Last Modified: 2013-12-13
Can I use PHP PDO(PHP Data Objects) to connect to SQL Server 2008? I can't seem to connect.
0
Comment
Question by:penname
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22768728
Show us what you have tried?
0
 

Author Comment

by:penname
ID: 22768828
I can connect to MySQL just fine using the following syntax:

$conn = new PDO("mysql:host=dev;dbname=testdb", "testuser", "testpassword");

But when I try to connect to either MS SQL Server 2000 or 2008 (do not have 2005) I get errors with either of these.
$conn = new PDO("mssql:host=dev;dbname=testdb", "testuser", "testpassword");
or
$conn = new PDO("odbc:host=dev;dbname=testdb", "testuser", "testpassword");

Thanks,
Mike
0
 

Author Comment

by:penname
ID: 22768956
I am running PHP 5.2.6
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22769011
Please set error_reporting(E_ALL) and show us what the errors say.
0
 

Author Comment

by:penname
ID: 22769145
When I trap PDO exception I get the following error (Although I am using the same credentials I use to connect from within NuSphere IDE and I have no problems finding the server from that environment):

'PDOException' with message 'SQLSTATE[01002] Unable to connect: SQL Server is unavailable or does not exist. Specified SQL server not found. (severity 9)'
0
 

Author Comment

by:penname
ID: 22769790
ok, thanks to the following link, I am able to get it connected to SQL Server 2000...so this is progress.  I still need to connect to 2008 though.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23670847.html

So the following works for 2000:

$conn = new PDO("odbc:Driver={SQL Server};Server=dev;Database=testdb;Uid=testuser;Pwd=testpassword", "testuser", "testpassword")
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22769904
penname: You've seen the examples here, right?

http://us2.php.net/manual/en/ref.pdo-dblib.php

They seem to want to point us in the direction of this:

http://us2.php.net/manual/en/ref.pdo-odbc.php

Grmmphff. ~Ray
0
 

Accepted Solution

by:
penname earned 0 total points
ID: 22769973
The syntax I mentioned above also works for 2008:

$conn = new PDO("odbc:Driver={SQL Server};Server=dev;Database=testdb;Uid=testuser;
Pwd=testpassword", "testuser", "testpassword")

or

$conn = new PDO("odbc:Driver={SQL Server Native Client 10.0};Server=dev;Database=testdb;Uid=testuser;
Pwd=testpassword", "testuser", "testpassword")

both work.  so I guess I have my answer.

thanks.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22770018
Congrats!  Good day's work. ~Ray
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

730 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