php pdo odbc mssql server through unixODBC problem

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am

Mon Apr 12, 2010 1:56 am

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: Select all

$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.

$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}'");

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

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

//The first statement produces expected result
//while the second statement produces empty array. Array()
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

Post Reply