You are here: Re: PDO - setFetchMode() before each getting? « PHP Programming Language « IT news, forums, messages
Re: PDO - setFetchMode() before each getting?

Posted by Michael Fesser on 06/17/07 17:39

..oO(webcm123@gmail.com)

>Must I use PDOStatement->setFetchMode() before each fetching data if I
>want to get only or usually ASSOC arrays? Perhaps, not.
>
>foreach( $stmt as $array ) { ... }
>
>It's the fastest way for fetching records to $array from result. So I
>have to insert $stmt -> setFetchMode(PDO::FETCH_ASSOC) before each
>Foreach.

Nope.

>Simply - lack of PDO->defaultFetchMode(). No one thought about it
>creating PDO. Who can tell PHP or PDO developers about it?

There's no need for such a function, because of:

>Or:
>PDO->setAttribute(PDO::FETCH, PDO::FETCH_ASSOC);

If you still want to have a defaultFetchMode() method you can always
write your own. Just derive a child class from PDO and implement that
method. But it's not really necessary.

>Why does PDO have constants instead of parameters?

Using constants provides flexibility, reliability and portability. You
don't have to care about the real internal (often numeric) value, since
you just use the descriptive and more readable constant.

>Typing PDO::[...]
>isn't so comfortable and I wonder if it isn't slower.

You have to use the PDO:: prefix, because the constants are defined
inside the PDO class. Since PHP doesn't support namespaces, this is
quite a good idea to avoid name conflicts in the global namespace.

If I want to use similar names in one of my own classes for whatever
reason, I can do that without any problems:

class TExample {
const FETCH_ASSOC = 1;
const FETCH_NUM = 2;
...
}

Same name, but different namespace.

Micha

 

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

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