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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:02:49+00:00 2026-05-18T11:02:49+00:00

Fatal error: Call to a member function prepare() on a non-object Is what I

  • 0

Fatal error: Call to a member function prepare() on a non-object

Is what I am getting when I try to do:

$sql = $connect->prepare ("SELECT id, pwd, firstname, lastname, approved, user_level FROM users WHERE $user_cond AND banned = 0"); // SELECT
$sql->execute ();
$sql->setFetchMode(PDO::FETCH_ASSOC);
$num = $connect->rowCount();

Im holding on rewriting my system, taking out all mysql_* and make use of pdo instead.

This is what was before:

$result = mysql_query("SELECT `id`,`pwd`,`firstname`,`lastname`,`approved`,`user_level` FROM users WHERE 
           $user_cond
            AND `banned` = '0'
            ") or die (mysql_error()); 
$num = mysql_num_rows($result);

What have I done wrong?

And with list() I have:

list($id,$pwd,$firstname,$lastname,$approved,$user_level) = mysql_fetch_row($result);

instead of mysql_fetch_row($result); what should I do in PDO?

My PDO object/connection:

try{
$connect = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset:UTF-8", DB_USER, DB_PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch(PDOException $pe)
{
  die('Could connect to the database because: ' .$pe->getMessage());

}

  • 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-18T11:02:50+00:00Added an answer on May 18, 2026 at 11:02 am

    Fatal error: Call to a member function
    prepare() on a non-object

    usually means that something failed and your variable is not what you expect it to be. $connection is probably false.

    PDOStatement::fetch

    list($id,$pwd,$firstname,$lastname,$approved,$user_level) = $sql->fetch();
    

    Also call rowCount on the statement, not on the connection:

    $sql->rowCount();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im getting Fatal error: Call to a member function prepare() on a non-object Error
I'm getting: Fatal error: Call to a member function setAccessToken() on a non-object in
I'm getting: Fatal error: Call to a member function query() on a non-object in
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\system\application\models\users_model.php on
Fatal error: Call to a member function query() on a non-object on line: $result
Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php
Fatal error: Call to a member function __toString() on a non-object in /home/ **/public_html/**
Magento is returning Fatal error: Call to a member function setQuote() on a non-object
I am getting this error Fatal error: Call to a member function hasResource() on
This code get an error : Fatal error: Call to a member function prepare()

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.