Note that there are some explanatory texts on larger screens.

plurals
  1. POCall to a member function bind_param() on a non-object not working inside function called from another function
    primarykey
    data
    text
    <p>I'm receiving the error above in the get_template() function of my class listed below. Does anyone know why I am receiveing this error? All of the other queries execute fine and $template_number is definitely returning an int which is expected at this point in the query so why am I receiving this error? Could it be because the return on this query is formatted as TEXT in MySQL (and appears as a BLOB in PHPMyAdmin?</p> <pre><code> class Page{ private $con; public function __construct(Connection $con) { $this-&gt;con = $con; if(isset($_GET['id'])){ $id = $_GET['id']; }else{ $id = 1; } $this-&gt;get_headers($id); $this-&gt;get_content($id); $this-&gt;get_footer($id); } private function get_headers($pageId){ $retrieveHead = $this-&gt;con-&gt;prepare("SELECT headers FROM pages WHERE page_id=?"); $retrieveHead-&gt;bind_param('i',$pageId); $retrieveHead-&gt;execute(); $retrieveHead-&gt;bind_result($header); $retrieveHead-&gt;fetch(); $retrieveHead-&gt;close(); echo $header; } private function get_footer($pageId){ $retrieveFooter = $this-&gt;con-&gt;prepare("SELECT footer FROM pages WHERE page_id=?"); $retrieveFooter-&gt;bind_param('i',$pageId); $retrieveFooter-&gt;execute(); $retrieveFooter-&gt;bind_result($footer); $retrieveFooter-&gt;fetch(); $retrieveFooter-&gt;close(); echo $footer; } private function get_content($pageId){ $retreiveContent = $this-&gt;con-&gt;prepare("SELECT template_id, section_title, i1, i2 FROM content WHERE page_id=? ORDER BY sequence DESC"); $retreiveContent-&gt;bind_param('i',$pageId); $retreiveContent-&gt;execute(); $retreiveContent-&gt;bind_result($template_id, $section_title, $i1, $i2); while ($retreiveContent-&gt;fetch()) { //Variables will be populated for this row. //Update the tags in the template. $template = $this-&gt;get_template($template_id); $template = str_replace('[i1]',$i1,$template); $template = str_replace('[i2]',$i2,$template); //$theTemplate is populated with content. Probably want to echo here echo $template; } $retreiveContent-&gt;close(); } private function get_template($template_number){ $retreiveFunction = $this-&gt;con-&gt;prepare("SELECT code FROM templates WHERE template_id=?"); $retreiveFunction-&gt;bind_param('i',$template_number); $retreiveFunction-&gt;execute(); $retreiveFunction-&gt;bind_result($template); $retreiveFunction-&gt;fetch(); $retreiveFunction-&gt;close(); return $template; } } </code></pre> <p>Table structure can be found below:</p> <p><img src="https://i.stack.imgur.com/xH2tl.jpg" alt="Table Structure"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload