Trying to see if I can make PDO open my mssql database on my server. With vbscript my call to the connection looks like this:
set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open("dsn=MYDSN;uid=MYUID;pwd=MYPWD;DATABASE=MYDATABASE;APP=ASP Script")
Then when trying to port this over to php using PDO I was unable to find any information on using DSN with PDO.
Here is what I have so far:
try {
$conn = new PDO('mssql:Server=localhost;Database=MYDSN','MYUID','MYPWD') or die('error');
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT name FROM people";
$qresult = $conn->prepare($sql);
$qresult->execute();
foreach ($qresult->fetch(PDO::FETCH_ASSOC) as $row){
echo $row['name'].'<br/>';
}
} catch (PDOException $e) {
print "Error!: ".$e->getMessage()."<br/>";
die();
}
But this is what I get
Error!: SQLSTATE[HY000]: General error: 10007 Invalid object name 'name'. [10007] (severity 5) [(null)]
My guess is because I cannot put the dsn anywhere in the pdo code.