Re: [PHP-DB] Another PDO ?
Jim, We have code that operates on tables that can be altered by users of the application (effectively storing different types of user data for each client). Some routines fetch results with PDO::FETCH_NUM as opposed to PDO::FETCH_ASSOC (or others), particularly when returning large amounts of data and performing manipulations on it in the code as well. columnCount can be useful here. (In fact, it comes from the mysql library directly, if I'm reading the code correctly.) -Matt On 09/10/2012 10:57 AM, Jim Giner wrote: On 9/10/2012 10:53 AM, Graham H. wrote: I think it's so that you could write functions as generically as possible. So you don't have to pass in the number of columns or hard code in values for number of columns, you can dynamically check the column count for each result set that gets passed in. That's my guess. On Mon, Sep 10, 2012 at 8:51 AM, Jim Giner wrote: On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I have not yet had a design where the results of queries could be handled generically. Yes I may save some coding time in one way, but for each field in a result the handling is not usually the same, therefore my code would have to specify unique field names at some point. This would only apply to a query that used * instead of distinct names too. To me it seems a function with rather limited use. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
On 9/10/2012 4:54 PM, Jim Giner wrote: On 9/10/2012 11:10 AM, Lester Caine wrote: Jim Giner wrote: On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... You do not necessarily KNOW how many fields. You know how many fields should be in the version of the database you are coding for, so any difference would flag a problem. Also you may not ACTUALLY have the schema for a database in which case a count of the fields found is useful for further processing those fields. Another area is when you are working with fabricated joined queries where duplicate field names between tables will give a reduced number of final fields in the result. Of cause it IS often better to work with named fields rather than using '*' which does allow better handing of the process anyway. I find it difficult to fathom a scenario where I am able to write queries against a db but not have access to the layouts. Makes it kind of hard to know what I'm going to get back but I guess it must occur somewhere since someone decided this function was necessary. You have access to the source table layouts, but it is possible to do pivot table type queries where the resultant table bears no resemblance to any of the source tables, and the number of columns in your result depends on the data. Toby -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
On 9/10/2012 11:10 AM, Lester Caine wrote: Jim Giner wrote: On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... You do not necessarily KNOW how many fields. You know how many fields should be in the version of the database you are coding for, so any difference would flag a problem. Also you may not ACTUALLY have the schema for a database in which case a count of the fields found is useful for further processing those fields. Another area is when you are working with fabricated joined queries where duplicate field names between tables will give a reduced number of final fields in the result. Of cause it IS often better to work with named fields rather than using '*' which does allow better handing of the process anyway. I find it difficult to fathom a scenario where I am able to write queries against a db but not have access to the layouts. Makes it kind of hard to know what I'm going to get back but I guess it must occur somewhere since someone decided this function was necessary. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
Jim Giner wrote: On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... You do not necessarily KNOW how many fields. You know how many fields should be in the version of the database you are coding for, so any difference would flag a problem. Also you may not ACTUALLY have the schema for a database in which case a count of the fields found is useful for further processing those fields. Another area is when you are working with fabricated joined queries where duplicate field names between tables will give a reduced number of final fields in the result. Of cause it IS often better to work with named fields rather than using '*' which does allow better handing of the process anyway. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
Imagine if you are building a generic database framework, so you (dont have, but) can generalize your queries functions and abstract some tables info. 2012/9/10 Graham H. > I think it's so that you could write functions as generically as possible. > So you don't have to pass in the number of columns or hard code in values > for number of columns, you can dynamically check the column count for each > result set that gets passed in. That's my guess. > > On Mon, Sep 10, 2012 at 8:51 AM, Jim Giner >wrote: > > > On 9/10/2012 10:49 AM, Bastien Koert wrote: > > > >> On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner < > jim.gi...@albanyhandball.com> > >> wrote: > >> > >>> Reading up on the pdostatement class. Wondering what the intent of the > >>> columnCount function is. I mean, aren't the number of columns in a > >>> result > >>> known when you write the query? Granted, you might have some very > >>> complex > >>> query that you may not know the number, but for most queries you will > >>> know > >>> the columns you are expecting. So - what am I not seeing? > >>> > >>> -- > >>> PHP Database Mailing List (http://www.php.net/) > >>> To unsubscribe, visit: http://www.php.net/unsub.php > >>> > >>> > >> It might be for those cases where you run a select * from ... > >> > >> But - again - one already knows how many fields are in that table when > > one writes the query... > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > Graham Holtslander > Computer Systems Technologist > www.graham.holtslander.com > mene...@gmail.com >
Re: [PHP-DB] Another PDO ?
On 9/10/2012 10:53 AM, Graham H. wrote: I think it's so that you could write functions as generically as possible. So you don't have to pass in the number of columns or hard code in values for number of columns, you can dynamically check the column count for each result set that gets passed in. That's my guess. On Mon, Sep 10, 2012 at 8:51 AM, Jim Giner wrote: On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I have not yet had a design where the results of queries could be handled generically. Yes I may save some coding time in one way, but for each field in a result the handling is not usually the same, therefore my code would have to specify unique field names at some point. This would only apply to a query that used * instead of distinct names too. To me it seems a function with rather limited use. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
I think it's so that you could write functions as generically as possible. So you don't have to pass in the number of columns or hard code in values for number of columns, you can dynamically check the column count for each result set that gets passed in. That's my guess. On Mon, Sep 10, 2012 at 8:51 AM, Jim Giner wrote: > On 9/10/2012 10:49 AM, Bastien Koert wrote: > >> On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner >> wrote: >> >>> Reading up on the pdostatement class. Wondering what the intent of the >>> columnCount function is. I mean, aren't the number of columns in a >>> result >>> known when you write the query? Granted, you might have some very >>> complex >>> query that you may not know the number, but for most queries you will >>> know >>> the columns you are expecting. So - what am I not seeing? >>> >>> -- >>> PHP Database Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> It might be for those cases where you run a select * from ... >> >> But - again - one already knows how many fields are in that table when > one writes the query... > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Graham Holtslander Computer Systems Technologist www.graham.holtslander.com mene...@gmail.com
Re: [PHP-DB] Another PDO ?
On 9/10/2012 10:49 AM, Bastien Koert wrote: On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: Reading up on the pdostatement class. Wondering what the intent of the columnCount function is. I mean, aren't the number of columns in a result known when you write the query? Granted, you might have some very complex query that you may not know the number, but for most queries you will know the columns you are expecting. So - what am I not seeing? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It might be for those cases where you run a select * from ... But - again - one already knows how many fields are in that table when one writes the query... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Another PDO ?
On Mon, Sep 10, 2012 at 9:48 AM, Jim Giner wrote: > Reading up on the pdostatement class. Wondering what the intent of the > columnCount function is. I mean, aren't the number of columns in a result > known when you write the query? Granted, you might have some very complex > query that you may not know the number, but for most queries you will know > the columns you are expecting. So - what am I not seeing? > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > It might be for those cases where you run a select * from ... -- Bastien Cat, the other other white meat -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php