473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

PDO - setFetchMode() before each getting?

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.

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

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

Why does PDO have constants instead of parameters? Typing PDO::[...]
isn't so comfortable and I wonder if it isn't slower.

Jun 17 '07 #1
2 3754
On Jun 17, 12:39 pm, webcm...@gmail.com wrote:
Must I use PDOStatement->setFetchMode() before each fetching data if I
want to get only or usually ASSOC arrays? Perhaps, not.
You could just try it and find out.
>
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.

Simply - lack of PDO->defaultFetchMode(). No one thought about it
creating PDO. Who can tell PHP or PDO developers about it?
You can. There are plenty of places on the PHP website where you can
request features, report bugs, or just whine about things.
>
Or:
PDO->setAttribute(PDO::FETCH, PDO::FETCH_ASSOC);

Why does PDO have constants instead of parameters? Typing PDO::[...]
isn't so comfortable and I wonder if it isn't slower.
So that PDO constants don't clash with other constants defined in the
global scope. Just because it's uncomfortable for you to type
doesn't make it wrong or incorrect. And I doubt there is any
practical difference in access speed.

Jun 17 '07 #2
..oO(we******@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
Jun 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jd | last post by:
Hi, I have an xsl as below. I am trying to loop using <xsl:for-each> and in the select attribute of <xsl:for-each> i am getting the nodeset from the external javascript function in the <CDATA>...
9
by: JW | last post by:
Dear NG, Still working on my .NET CF C# forms application ... I have an array of forms that I wish to display in array order, and thus have created a loop to run through them. Due to...
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
13
by: tshad | last post by:
Is there a way to run a script or function on entry of each page without having to put a call in each page? Periodically, I find something I want to do each time a page is entered and I have to...
4
by: gabe | last post by:
i have a solution to gather the text in each window that is open, but would rather use only managed code rather than unmanaged code my current solution relies on. The purpose is to get the text in...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
2
by: dkmd_nielsen | last post by:
I have two rather simple class methods coded in Ruby...my own each iterator: The iterator is used internally within the class/namespace, and be available externally. That way I can keep...
0
by: DR | last post by:
I set my database to trustworthy and deployed this clr stored proc as unsafe ok but when i run this it returns 1 each time. as if ival keeps getting set back to 0 each time i call this clr stored...
1
by: ll | last post by:
Hi all, I've inherited a site and am currently looking to redesign a page that displays a table of course curriculum, with each row representing a "Topic" of the curriculum. There is a courseID...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.