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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:23:45+00:00 2026-06-06T14:23:45+00:00

I have problem with php script. The thing is that it shows me, that

  • 0

I have problem with php script.
The thing is that it shows me, that I am calling to a function of a non-object, but the object exists.

Script is:

if ($dcdt_sql['pdo']) {
try {
    $dbh = new PDO(
        'mysql:host='.$dcdt_sql[0].';dbname='.$dcdt_sql[3],
        $dcdt_sql[1],
        $dcdt_sql[2],
        array(
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
            PDO::ATTR_PERSISTENT => false
        )
    );
}
catch (PDOException $e) { die("PDO ERR: [".$e->getMessage()."]"); }
}
else { $dbh = DBManager::connect(); }

switch ($mode) {
case 'fetch_assoc':
    if ($dcdt_sql['pdo']) {
        try {
            $sth = $dbh->prepare($sqlQuery)->execute();
            $result = $sth->fetchAll(PDO::FETCH_ASSOC); // PROBLEM IS IN THIS LiNE
            $return = $result;
        }
        catch (PDOException $e) { die("PDO ERR: [".$e->getMessage()."]"); }
    }
    else {
        $result = $dbh->query($sqlQuery);
                    if (!is_object($result)) { die('DEBUG: Query error: ['.$sqlQuery.'] returned: ['.print_r($result,1).']'); }//DEBUG
        while ($row = $result->fetch_assoc()) {
            $list[] = $row;
        }
        $return = $list;
    }
break;

Problem is where I commented it, but it should be an object whos function is called.
So I don’t get it.

Error I get:

Fatal error: Call to a member function fetchAll() on a non-object in /usr/local/www/apache22/data/centrs/dc_elec/report.lib.inc on line 102

Thank You in advance.

  • 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-06T14:23:48+00:00Added an answer on June 6, 2026 at 2:23 pm

    http://sg.php.net/manual/en/pdostatement.fetchall.php

    Correct usage as dictated:

    <?php
    $sth = $dbh->prepare("SELECT name, colour FROM fruit");
    $sth->execute();
    
    /* Fetch all of the remaining rows in the result set */
    print("Fetch all of the remaining rows in the result set:\n");
    $result = $sth->fetchAll();
    print_r($result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really confusing problem. I have a PHP script that polls another
I have the following php script that is called by jquery ajax function report_range($time,
I have a bizzare problem with php date function. code: $numDays = 8; $date
I have problem with session in cakephp.I have one file chat.php that is in
I have a server-side php-script that fetches results from a MySQL table. I am
I have a php script that I have used for years to force downloads
I have a script that enables artists to edit their profile. One thing is
I have a problem with running lame encoder via shell_exec script in php. And
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I have a problem in php code inserting values into database (I use PHPMyAdmin).

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.