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 6627961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:04:29+00:00 2026-05-25T22:04:29+00:00

Twice now I’ve mistakenly used row() instead of row_array() when fetching a single row

  • 0

Twice now I’ve mistakenly used row() instead of row_array() when fetching a single row result. Usually, it goes unchecked without any warning messages. 15-30 minutes later I finally notice the issue; doh doh!

Does anyone have any good suggestions as to ways to prevent this mistake. The object format doesn’t throw a PHP warning, but – of course – the code doesn’t work when you expect an array from a model method.

I accidentally used:

if ($query->num_rows() > 0) {
    return $query->row();
}

Which should instead be:

if ($query->num_rows() > 0) {
    return $query->row_array();
}

I thought about overriding the row() database method and adding in a log_message() statement that would at least let me know (on debug level) that I’m using the object format, instead of the much more typical (for my code) format.

  • 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-05-25T22:04:30+00:00Added an answer on May 25, 2026 at 10:04 pm

    The only way to “prevent” is pretty much learn over the documentation again so you can keep a common habit of using which function.

    You can note yourself, if you are going to return multiple records, use the row_array(), for a singular record, use the row() function.

    Remember, don’t speed type your code, proofread your code step by step before continuing.

    Overriding the original function is bad practice, using the row() function is useful when retrieving a singular record, so don’t do this.

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

Sidebar

Related Questions

Twice now in git, I've meant to branch from master, but instead branched from
I have encountered a problem twice now whereby a producer thread produces N work
I went through the dev portal provisioning process twice now trying to get it
Would it be possible to print Hello twice using single condition ? if condition
I've installed Microsoft SQL Server 2008 Express twice now, and all the services work
Now i have to click the Home button twice and press one app until
This has actually occurred twice now. I'm writing a cross-platform application, and some of
I have had my shared web server suspended twice now for moving large files
I work in a large scale IT support environment. Twice now we have seen
I just found myself copying and pasting the same code twice. Right now I

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.