Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:17:46+00:00 2026-06-14T01:17:46+00:00

I have a simple pdo prepared query: $result = $db->prepare(select id, course from coursescompleted

  • 0

I have a simple pdo prepared query:

$result = $db->prepare("select id, course from coursescompleted where person=:p"); 
$result ->bindParam(':p', $q, PDO::PARAM_INT);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
echo $rows[0];

the echo seems to be returning the ID value of the record, not the number of records returned by the query?

any idea or explanation for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:17:47+00:00Added an answer on June 14, 2026 at 1:17 am

    PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0

    You aren’t fetching the row-count at all.

    SELECT COUNT(*) FROM coursescompleted where person=:p
    

    This query would return total rows in $rows[0];

    EDIT:
    Please see @ray’s answer. using count(id) is better than count(*) for InnoDB.


    You could get row-count in the following manner, from your earlier query.

    $row_count = $result->rowCount();
    

    But be warned:

    If the last SQL statement executed by the associated PDOStatement was
    a SELECT statement, some databases may return the number of rows
    returned by that statement. However, this behaviour is not guaranteed
    for all databases and should not be relied on for portable
    applications.

    Documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $link = new PDO(mysql:dbname=$databasename;host=127.0.0.1,$username,$password); $query = $link->prepare(SELECT * FROM
i have simple singleton that sets pdo object from factory class , in the
Simple question and i want simple answer. I'm using PDO prepared statements to make
I have a PDO prepared statement in which the bound variables are prepared dynamically
currently I have a simple search query which works as follows: $username = $_SESSION['username'];
Possible Duplicate: Can you put placeholders in select part of a query using PDO?
I'm attempting to make a simple query library and I'm using PDO for database
I am new to PDO and I have pretty simple question. I have a
I'm creating a simple query builder for PHP PDO, to create queries faster, without
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.