#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Cape Town, WP, South Africa
    Posts
    39
    Rep Power
    15
    How do you count the number of rows returned from your query. at the moment I am trying

    $sth = $dbh->prepare("select *
    FROM Customer ");

    $numrows = $sth->execute;

    but it is giving me -1

    any ideas
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    5
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by chrisdice4:
    How do you count the number of rows returned from your query. at the moment I am trying

    $sth = $dbh->prepare("select *
    FROM Customer ");

    $numrows = $sth->execute;

    but it is giving me -1

    any ideas
    [/quote]


    Using MySQL (and maybe other DBD drivers), there is a method, '$sth->rows();', that you can call afgter the execute(). Using other DBD's (or writing to be portable), you can simply count the rows as you fetch them.

    Or you could change the SQL: 'select count(*) from Customer;' and that will rerurn a single scalar that is the number of rows.

    BTW, I have no idea where the -1 comes from but I think it's an error code. If so, it's because your SQL isn't legal (you need to end with a semi-colon). And in a UNIX envrionment, the table names are liable to be case sensitive (so make sure customer has a capital C). You've only shown a snippet, but beware that you *must* be checking for failed function calls if you care at all how this application works.

    -Alan

IMN logo majestic logo threadwatch logo seochat tools logo