You are here: Re: Weird problem with PDO/ODBC and Access « PHP Programming Language « IT news, forums, messages
Re: Weird problem with PDO/ODBC and Access

Posted by ImOk on 10/31/75 11:55

It seems to happen with a short table too.
I am using PHP5.1 under Windows XP of course.

I made a small table and added 2 rows with info in all columns and here
is the layout:

LastName - text,
notes - memo,
addr - text,
zip - text

Here is the code. It fails in $cursor and $cursor1 but works when notes
is last in $cursor2.

<?php
$tbl='tblNotes';

$user='';
$pass='';
$conn = "DSN=mailing;Driver=Microsoft Access Driver";
try {
$dbh = new PDO("odbc:$conn", $user, $pass);

// prints nulls after NOTES
$cursor=$dbh->query("SELECT * from $tbl order by LastName");
foreach ($cursor as $row) {
$row=array_change_key_case($row, CASE_UPPER);
echo $row['LASTNAME'] . '|';
echo $row['NOTES'] . '|';
echo $row['ADDR'] . '|';
echo $row['ZIP'] . '|';
echo "\n";
}
echo "\n";

// Also prints nulls after NOTES
$cursor1=$dbh->query("SELECT LastName, notes, addr, zip from $tbl
order by LastName");
foreach ($cursor1 as $row) {
$row=array_change_key_case($row, CASE_UPPER);
echo $row['LASTNAME'] . '|';
echo $row['NOTES'] . '|';
echo $row['ADDR'] . '|';
echo $row['ZIP'] . '|';
echo "\n";
}
echo "\n";

// prints all columns correctly because I moved notes to be last
$cursor2=$dbh->query("SELECT LastName, addr, zip, notes from $tbl
order by LastName");
foreach ($cursor2 as $row) {
$row=array_change_key_case($row, CASE_UPPER);
echo $row['LASTNAME'] . '|';
echo $row['NOTES'] . '|';
echo $row['ADDR'] . '|';
echo $row['ZIP'] . '|';
echo "\n";
}

} catch (PDOException $e) {

echo $e->getMessage();

}
$dbh = null;
?>


Result when you run this:
$cursor
doe|mm|||
smith|xx|||

$cursor1
doe|mm|||
smith|xx|||

$cursor2
doe|mm|120 main street|10006|
smith|xx|320 bway|10007|

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация