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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:56:10+00:00 2026-05-25T14:56:10+00:00

I have this function public function populate($id) { $pdo = new PDOConfig(); $sql =

  • 0

I have this function

public function populate($id) {
    $pdo = new PDOConfig();

    $sql = "SELECT * FROM ".$this->table." WHERE `id` = :id";

    $q = $pdo->prepare($sql);
    $q->execute(array(":id"=>$id));
    $resp = $q->fetchAll();
    foreach ($resp as $row) {
        foreach ($row as $key=>$value) {
            if(!is_int($key))
                $this->$key = html_entity_decode($value, ENT_QUOTES);
            if($value == null) {
                $this->$key = null;
            }
        }
    }

    $pdo = null;
    unset($pdo);
}

Which works.
When I try to make

$sql = "SELECT * FROM ".$this->table." WHERE `id` = :id";

into

$sql = "SELECT * FROM ".$this->table." WHERE `id` = :id AND `life` > 0";

It breaks. When I run this function in sql within terminal however, all works fine. The table has the field life and for sure the query should work. What am I missing?

Thanks

  • 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-25T14:56:11+00:00Added an answer on May 25, 2026 at 2:56 pm

    You haven’t posted here neither the real SQL query generated by your PHP code nor the value of the $id variable. This leads me to think that you haven’t really inspected them. So when you say «I run this function in sql within terminal however, all works fine» you are probably referring to the SQL query you intend to create. Thus the issue is that your PHP code does not send the query and values you think it does.

    Troubleshooting steps:

    1. Right before $q->execute(array(":id"=>$id));, inspect the values of $sql and $id. You can use var_dump() or your debugger of choice. In the first case, don’t trust your browser rendered view; instead, use the View Source menu.

    2. Compare those values with the expected result.

    3. Make sure your PDO subclass captures errors. The simplest way is to make a SQL syntax error on purpose, such as XSELECT * FROM.

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

Sidebar

Related Questions

I have a situation where i want to return List<> from this function public
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
I have this function: Program A public ICollection<ReportLocationInfo> GetAllReportsInstalled() { return _Reports; } I
How would I create a nested list, I currently have this public function getNav($cat,$subcat){
I have this function which returns a datatype InetAddress[] public InetAddress [] lookupAllHostAddr(String host)
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this user defined function. public partial class UserDefinedFunctions { static int i;
i have a class of this kind Class Car { private $color; public function
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
I have a function that I use to add vectors, like this: public static

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.