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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:49:18+00:00 2026-06-04T15:49:18+00:00

I have this problem I can’t figure out, I query the DB this way:

  • 0

I have this problem I can’t figure out,
I query the DB this way:

$stmt = $this->pdo->prepare('SELECT customer_name FROM active_users WHERE a_id= ?');
$stmt->execute(array($a_id));
$c_name = $stmt->fetch(PDO::FETCH_OBJ);
API::writeToLog('CMD=leave , Customer_Name = ' . $c_name->customer_name, $customer_name);

This: $c_name->customer_name gives the following error :

Notice: Trying to get property of non-object

How can I iterate my database, and whats the difference between fetch and fetchAll ? which should I use?

This is the DB schema:

+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| a_id          | varchar(40)  | NO   | PRI | NULL    |       |
| token         | varchar(64)  | NO   |     | NULL    |       |
| nick          | varchar(255) | NO   |     | NULL    |       |
| ip            | varchar(32)  | NO   |     | NULL    |       |
| customer_name | varchar(255) | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+

thanx!

EDIT: fixed a typo..

  • 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-04T15:49:20+00:00Added an answer on June 4, 2026 at 3:49 pm

    You should add an if condition to check whether the record exists.

    $stmt = $this->pdo->prepare('SELECT customer_name FROM active_users WHERE udid = ?');
    $stmt->execute(array($udid));
    if ($c_name = $stmt->fetch(PDO::FETCH_OBJ)) {
      API::writeToLog('CMD=leave , Customer_Name = ' . $c_name->customer_name, $customer_name);
    }
    

    For fetchAll, it returns all the records at once.

    As @Darragh pointed out, you have a typo for $c_name.

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

Sidebar

Related Questions

I have this code and can't figure out what seems to be the problem:
I have this problem, and I can't figure it out whats is wrong. I
I have had this problem crop up a few times and I can't figure
can you help me with sql query? I have this problem: I have two
I have this problem that I cannot fix. From my @Controller , i can
I have this problem that I can ref a button for control it. I
I have worked on this problem for my entire day and can't solve it.
I have a problem that I can't resolve. Let's say I have this map
I'm quite new to hibernate and have stumbled on this problem, which I can't
I can't fix this problem on my listview template: i have the error as

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.