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

  • Home
  • SEARCH
  • 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 7978669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:33:06+00:00 2026-06-04T09:33:06+00:00

Hello i was trying to make function with PDO but getting error (new to

  • 0

Hello i was trying to make function with PDO but getting error (new to PDO) here is my code

    function mail_id($mail){
    global $host, $dbname, $user, $pass;
    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $STH = $DBH->query("select count(from) from messages where from = '$mail'");
    $STH->setFetchMode(PDO::FETCH_ASSOC);
    $row = $STH->fetch();
    return $row;
}

i want to count row FROM and here is the out put i was trying

$mail=mail_id($userid);
if (0<count($mail['to_viewed'])) {echo "green";} else {echo "gray";}

this is the error

Call to a member function setFetchMode() on a non-object

please help thx

  • 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-04T09:33:07+00:00Added an answer on June 4, 2026 at 9:33 am

    You need to check the return value of PDO::query(). In (ugly) PHP there are lots of functions that return a value of mixed type. In the case of PDO::query() the return type is either PDOStatement or bool, although the prototype in the documentation says something different:

    Description:
    PDOStatement PDO::query ( string $statement )
    ...

    Looks like it always returns PDOStatement.

    Return Values:
    PDO::query() returns a PDOStatement object, or FALSE on failure.

    Oops, not in every case! Therefore you are not guaranteed that the value returned is a PDOStatement.

    The correct prototype would be:

    Description:
    mixed PDO::query ( string $statement )
    ...

    In your case the query is invalid (by using a reserved keyword like FROM as a column name) which results in a return value of type boolean with the value FALSE. A boolean value is not an object and therefore your call to $STH->setFetchMode() fails.

    Depending on your PDO::ATTR_ERRMODE you get

    • an exception (PDO::ERRMODE_EXCEPTION), so you don’t need to check the
      return value
    • a warning (PDO::ERRMODE_WARNING)
    • nothing (PDO::ERRMODE_SILENT), so you have to check the return value, errorCode() and errorInfo()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello im trying to make something like github treeslider im new to javascript.. but
Hello i am trying to make function with while loop in php but cant
Hello guys look to my code I'm trying to make a program which asks
I am trying to do make a C++ hello world that supports Unicode, but
Hello i am trying to return a struct from a function but i cant
Hello this might be really silly question but I am trying to make markers
hello im new and learning javascript. I'm trying to make a program of addition
Hello all im new to jquery and im trying to make a edit inplace
I am trying to make a Demo in Appcelerator here is the code for
Hello i'm trying to make a tag script for my website so each time

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.