php pdo odbc mssql server through unixODBC problem

A

Anonymous

Guest
Hi everyone,

Recently, I've been working on a project which uses php + Microsoft Sql Server. I've chosen pdo odbc with unixODBC database driver. At this moment, I'm facing a problem with multiple select statement. Below is my code:

Code:
<?php
$dbh = new PDO('odbc:dsn_name','user_name','password');

////////If I added this line, I could see the error message. But I couldn't find any way out about that.
//$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$username = 'makarakao';

//PDO Statement
$stmt = $dbh->prepare("SELECT user_id,username,status FROM users WHERE username='{$username}'");
$stmt2 = $dbh->prepare("SELECT user_id,username,status FROM users WHERE username='{$username}'");

$stmt->execute();
$rowuser = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();

$stmt2->execute();
$rowuser2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
$stmt2->closeCursor();

//The first statement produces expected result
print_r($rowuser);
//while the second statement produces empty array. Array()
print_r($rowuser2);
?>

As you can see, I expect I'll get the same result within these two variables ($rowuser and $rowuser2). But what I get is only $rowuser while $rowuser2 returns an empty Array. I've noticed that whenever I use multiple PDO Statement with select statement.

I've been trying to look for the documents about this issue. But there's no luck cos there are few documents about pdo. And the project needs releasing soon. Hope anyone of you guys can help.

Thanks in advance,
Makara Kao
 
Back
Top