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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:24:13+00:00 2026-06-18T12:24:13+00:00

This has been driving me crazy, the issue is I cannot work out How

  • 0

This has been driving me crazy, the issue is I cannot work out How i can get and set the cached data to be displayed within my view.

public function get_something($id, $account_name)
{
    $sql = "SELECT one,two,three FROM table WHERE id = ? and account_name = ? ";
    $key = md5("SELECT one,two,three FROM table WHERE id = $id and account_name = $account_name ");

    $get_result = $this->Core->Core->Memcache->get($key);

    if($get_result)
    {
      // How would I set the Data
    }
    else
    {
     $stmt = $this->Core->Database->prepare($sql);
     $stmt->bind_param("is", $id, $account_name);
     $stmt->execute();
     $stmt->store_result();
     $stmt->bind_result($one, $two, $three);
     $stmt->fetch();
     //Below is how i set the data
     $this->Core->Template->set_data('one', $one);  
     //Set the Memcache
     $this->Core->Memcache->set($key, $stmt, TRUE, 20);
}

So my question is how can I get and set the data from a prepared statement fetch within memcache?

  • 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-18T12:24:14+00:00Added an answer on June 18, 2026 at 12:24 pm

    Memcache is a key/value storage system with both the key and the value needing to be serialized. From the php.net page:

    Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache, because they cannot be adequately represented in serialized state.

    It appears your sql statement is looking for three values in a single row. I’m no expert on mysqli, but this is kind of what you want to do:

    public function get_something($id, $account_name){
      $sql = "SELECT one,two,three FROM table WHERE id = ? and account_name = ? ";
      $key = md5("SELECT one,two,three FROM table WHERE id = $id and account_name = $account_name ");
    
      $get_result = $this->Core->Core->Memcache->get($key);
    
      if($get_result){
        return $get_result;//#1 just return it, the format is an array like what is being built below
      }
      else{
       $stmt = $this->Core->Database->prepare($sql);
       $stmt->bind_param("is", $id, $account_name);
       $stmt->execute();
       $stmt->store_result();
       $stmt->bind_result($one, $two, $three);
       $stmt->fetch();
       //Below is how i set the data
       $this->Core->Template->set_data('one', $one);//#2 I don't know what this line does or is for, presumably for something else besides memcache stuff, maybe it acts like return
       //Set the Memcache
       $array=array();//#3
       $array[]=$one;
       $array[]=$two;
       $array[]=$three;
    
       $this->Core->Memcache->set($key, $array, TRUE, 20);
       //this is a function, do you want to return your values somewhere?
     }
    

    A few notes, #1 the answer to your question is simple, just return $get_result. It should be an array with three values. #2 I’m not familiar with this line, nor what it does. Is this how your “return” the values to your controller? If so, you’ll want to mimick that line where I put the return inside the if #3 This is your problem. You can’t save the $stmt variable in memcache, it’s a mysqli object, not the data you want. You need to build an array and then save that array. And that should do it for you.

    There are other nuances to do, you can loop on the returned values. You should check for mysql not returning anything. But this is the basic starting point to get this going.

    Let me know if this works for you.

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

Sidebar

Related Questions

This issue has been driving me crazy all morning. I've been trying to get
so I am having this issue that has been driving me crazy for hours,
This has been driving be crazy, but I can't seem to find an answer.
This has been driving me crazy all day. I need to get a font
I hope someone can help me. This has been driving me crazy for days.
This has been driving me crazy because I can't find anything on Google. Maybe
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy. I think I have everything in place but
he this has been driving me nutts, and I hope someone can shed some
I have an AutoMapper issue that has been driving me crazy for way too

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.