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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:09:53+00:00 2026-05-22T03:09:53+00:00

In an effort to tidy up my code, I’ve encapsulated my database reads into

  • 0

In an effort to tidy up my code, I’ve encapsulated my database reads into its own function, which accepts a SQL command for the argument, as well as an optional $getArray argument which specifies whether I am returning an array as the result (true for SELECT, false for UPDATE, etc).

function readDB($sql, $getArray = false)
{
    $conn = odbc_connect('myAccessDataBase', '', '');
    if (!$conn)
        return exit('Connection Failed: '.$conn);
    if ($getArray = false)
        odbc_exec($conn, $sql);
    else
    {
        $res = odbc_exec($conn, $sql);
        if (!$res)
            return exit('Error in SQL');
        return odbc_fetch_array($res);
    }
    odbc_close($conn);
}

The code above works as expected except for one small caveat. If I am performing an UPDATE vs a SELECT, I get a warning due to $getArray being set to false:

Warning: odbc_fetch_array() [function.odbc-fetch-array]: No tuples available at this result index in C:…\functions.php on line 14

I understand the warning, which makes sense if that line were to actually be executed, however it is not. My question is in regards as to why PHP is evaluating the contents of the else portion of my if statement, which is not even being hit during runtime. I understand that the UPDATE cannot return an array, hence why I am evaluating $getArray to determine whether I expect such a return. What can I do to circumvent this warning? Regardless, I am still pretty fresh with my PHP, and am probably going about this the wrong way anyhow. Cheers!

  • 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-22T03:09:54+00:00Added an answer on May 22, 2026 at 3:09 am

    You’re setting the variable TO FALSE instead of evaluating it FOR FALSE If you change this line:

    if ($getArray = false)

    to

    if ($getArray == false)

    It should work.

    edit

    On another note, you should do your test in reverse. Instead of testing for false, test for true and THEN have an else. It makes a little more sense logically for anyone coming in to look at your code later.

    Instead of If this IS NOT the case then do this it makes more sense to say if this is the case, do this

    So switch your code blocks around and test:

    if ($getArray)

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

Sidebar

Related Questions

I am making the effort to learn Vim. When I paste code into my
I'm in the middle of a significant effort to introduce NHibernate into our code
How do convert effort estimate say in function points to a specific web framework
In an effort to 'clean up' my code - I was wondering if this
I believe this code may require more effort to comprehend than average, so I'm
In the effort of building a live site on its actual live hosting platform
In an effort to create a sandbox for CoreGraphics development (which currently consists of
In an effort to move to TDD and unit testable code I have read
I'm diving into CSS in an effort to be more well-rounded. I'm currently reading
I've been tinkering with some code in a effort to understand OOP using c.

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.