Re: [PHP-DB] PDO user question
Brandon: RAM is cheap, but not always expendable depending on what you're doing. Using count() on results from PDOStatement::fetchAll() is fine on small result sets. Keep in mind that this will certainly blow up on very large result sets, especially depending on your memory_limit for php. Avoiding this problem is the primary reason I use prepared statements for retrieving data. If you're working with small result sets you could avoid using prepared statements altogether, which would greatly simplify doing something like getting a row count. If you don't absolutely need your code to be portable across multiple database servers, I would encourage you to experiment with the rowCount() method and see if it works for your setup. (I ran a quick test in my mysql environment and it worked fine for a SELECT statement. Sqlite doesn't seem to support it because the actual sqlite library doesn't support it. Haven't looked into postgres or others.) Another thing to be aware of (at least with mysql), and speaking to Lester's point, is that you can use SQL_CALC_FOUND_ROWS (with mysql, anyway) to get a total count when you are using LIMITs on your result set (which would be advisable if you're returning these results in a web interface). -Matt On 09/09/2012 02:40 PM, brandon wrote: That's how I'd do it. Extend the PDO interface on your abstract class to include a "num_rows()" method that utilizes that higher level count($this->result). It might be a little more overhead... but RAM is cheap... and there's always forking/extending the library in C/C++... -Brandon On 2012-09-09 11:49, Michael Stowe wrote: How are you using the number? Probably the easiest way is to utilize PDOStatement::FetchAll() and then do a count() on that result set. - Mike Sent from my iPhone On Sep 9, 2012, at 11:42 AM, Stefan Wixfort wrote: Hi Jim I've had some success with querying using pdo and prepared statements as well. One thing that I'm curious about is How does one handle the need to get the number of rows returned by a Select? The documentation is very clear that PDO doesn't return that value for a Select statement (depending upon driver?) and there were a couple of solutions that made no sense to me. There was even one that did a completely separate query just to get the row count which makes even less sense. I believe you are referring to "SELECT COUNT(*)..." Because I couldn't find a different way I use that. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Adding entry to /dev
On 9/10/2012 7:41 PM, Ethan Rosenberg, PhD wrote: Dear list - How do I add a new entry to /dev; eg, /dev/sdb? Thanks, Ethan Rosenberg Ethan, Sometimes google is great at answering this kind of stuff. Did you try a search on your question. I did and found an answer in the fifth result returned. Search on "php add a new subfolder" -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On 9/11/2012 12:04 AM, Matt Pelmear wrote: Ethan, I am curious why you are using mysqli_stmt_bind_result() on a statement that is an INSERT query? I don't use mysqli, but as I read the documentation it seems to me that this method is intended to bind results from a SELECT query into variables so that you can simply call mysqli_stmt_fetch() in a loop and have the variables magically contain the data from the next row. Perhaps mysqli is confused because you are both mapping data to be bound (with mysqli_stmt_bind_param()) and to be returned (with mysqli_stmt_bind_result()) on the same INSERT query? If you are just trying to insert, you should only need mysqli_stmt_bind_param() (which, by my count, has one parameter too many right now in your code) and mysqli_stmt_execute() (and probably not mysql_stmt_bind_param() and mysql_stmt_fetch()). See "Example #2" here: http://us.php.net/manual/en/mysqli-stmt.execute.php -Matt On 09/10/2012 08:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com If I had read further I would not have made my post a moment ago. Give Matt here the credit for seeing the forest thru the trees. :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problems w/ insert
On 9/10/2012 8:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg Ethan - PS to my other response: I think you should make a change to use the preferred syntax for the execute statement. The one you are using is deprecated, so will be removed in the future. May as well write code that isn't already on the way out. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On 9/10/2012 8:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com Ethan, This is almost the exact same problem you posted last week and we were unable to solve it then. Having said that I think I suddenly see it. An "INSERT" query does not return any 'result', as I believe the intent of the 'bind-result' call is designed for. If you were doing a SELECT to pull those fields from the table this would work I'm guessing. But since it is an INSERT, there are no fields to be bound. That is the error! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysqli_connect ??
Jim, You likely have to install the mysqli package for your distribution. Try a search for something like"ubuntu install php mysqli" or "centos install php mysqli" I can tell you for ubuntu you probably would need to do something like this: sudo apt-get install php5-mysql If you're in a hosted environment, you might be out of luck unless they'll install it for you :-) But I would also be surprised if a hosted environment was missing this package. -Matt On 09/07/2012 01:36 PM, Jim Giner wrote: No - they are not. :( On 9/7/2012 1:32 PM, Bastien Koert wrote: On Fri, Sep 7, 2012 at 10:54 AM, Jim Giner wrote: Experimenting with prepared statements - trying out for the first time. I keep getting a fatal error on this statement: mysqli_connect(.) Message is: Fatal error: Call to undefined function mysqli_connect() in /home/albany/php/sqli_db_connect_select.php on line 6 My host is running php 5.3.9 Can anyone clue me in? I copied my usage directly from the manual! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Check to see if mysqli_functions are enabled with phpinfo() -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
Ethan, I am curious why you are using mysqli_stmt_bind_result() on a statement that is an INSERT query? I don't use mysqli, but as I read the documentation it seems to me that this method is intended to bind results from a SELECT query into variables so that you can simply call mysqli_stmt_fetch() in a loop and have the variables magically contain the data from the next row. Perhaps mysqli is confused because you are both mapping data to be bound (with mysqli_stmt_bind_param()) and to be returned (with mysqli_stmt_bind_result()) on the same INSERT query? If you are just trying to insert, you should only need mysqli_stmt_bind_param() (which, by my count, has one parameter too many right now in your code) and mysqli_stmt_execute() (and probably not mysql_stmt_bind_param() and mysql_stmt_fetch()). See "Example #2" here: http://us.php.net/manual/en/mysqli-stmt.execute.php -Matt On 09/10/2012 08:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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] Adding entry to /dev
Ethan, I think you should be a little more specific about what your end goal is. -Matt On 09/10/2012 07:41 PM, Ethan Rosenberg, PhD wrote: Dear list - How do I add a new entry to /dev; eg, /dev/sdb? Thanks, Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *// The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problems w/ insert
Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Adding entry to /dev
Dear list - How do I add a new entry to /dev; eg, /dev/sdb? Thanks, Ethan Rosenberg -- 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
[PHP-DB] Re: PDO user question
On 9/8/2012 2:02 PM, Jim Giner wrote: I finally delved into learning how I was going to replace my MYSQL calls with a different interface. Had to go with PDO since my hoster doesn't support MYSQLI for my plan. I've had some success with querying using pdo and prepared statements as well. One thing that I'm curious about is How does one handle the need to get the number of rows returned by a Select? The documentation is very clear that PDO doesn't return that value for a Select statement (depending upon driver?) and there were a couple of solutions that made no sense to me. There was even one that did a completely separate query just to get the row count which makes even less sense. Will PDO ever come up with an accurate row count function? Does someone have a tried and true snippet they can share? For those looking for the answer to my question also, I've learne dthat this will work for 'small' result sets. My applications do not make requests for large result sets, so this works fine. $rows = $qrslts->fetchAll(PDO::FETCH_ASSOC); echo count($rows)." results found"; I suppose if I ever write up a new appl that will have to handle large query results, I'll have to come up with something else. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Another PDO ?
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