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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:40:05+00:00 2026-06-05T07:40:05+00:00

As my process is almost complete for rewriting web with PDO instead of mysql_*

  • 0

As my process is almost complete for rewriting web with PDO instead of mysql_* commands I am now testing my changed functions. And It seems that my changed function for mysql_result(mysql_query() always returns true, why is that? Lets see original and changed code:

if (mysql_result(mysql_query("SELECT COUNT(*) FROM account WHERE id='".$_SESSION["user_id"]."' AND online=1"), 0)>0)
{
  return true; 
}
else
  return false;

And changed code here:

$stmt = $db_login->prepare("SELECT COUNT(*) FROM account WHERE id=:id AND online=1");
$stmt->bindValue(':id', $_SESSION["user_id"], PDO::PARAM_INT);
$stmt->execute();
$results_login = $stmt->fetch(PDO::FETCH_ASSOC);
$rows = count($results_login);
if ($rows > 0)
{
  return true; 
}
else
  return false;

So what is wrong with is why it always returns true even when column has online=0? Thank you

  • 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-05T07:40:06+00:00Added an answer on June 5, 2026 at 7:40 am

    $stmt->fetch fetches one row from the result set. What you get out of that is an array containing all the selected columns, looking something like this:

    array(
        'COUNT(*)' => 42
    )
    

    A count() on that array will always result in 1.

    You need to check the contents of the fetched row:

    if ($result_login['COUNT(*)'] > 0)
    

    It’s best to alias this column to a nicer name:

    SELECT COUNT(*) AS `count` ...
    

    Then:

    if ($result_login['count'] > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that I need to run almost permanently. I've being using
I have a web form that users complete online. When they press submit it
Almost finished my java web app. All working fine. Whats next. I need now
I process a lot of text/data that I exchange between Python, R, and sometimes
I know next to nothing about the linking process, and it almost always gets
I am almost finished with my game now, but today I encountered a real
We have an automatic process that opens a template excel file, writes rows of
I'm currently looking for a way to optimize a process that takes a long
Alright, so I'm building a web app that provides music information (i.e. info on
When invoking the 'java' process, I'm almost certain there is a way to have

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.