Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

php pdo odbc mssql server through unixODBC problem

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

Moderators: macek, egami, gesf

php pdo odbc mssql server through unixODBC problem

Postby makarakao » 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
<?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
makarakao
New php-forum User
New php-forum User
 
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am

Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron