Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure if that's the issue, but this is what jumps out when i read your code:</p> <p>Your serialized object relies on a mysql connection </p> <blockquote> <p>$template = new Template($mysqli);</p> </blockquote> <p>while your object (maybe) can be serialized and un-serialized without problems, the mysql connection can't, so your un-serialized $template tries to operate on an invalid connection/file handle.</p> <p>You can try re-attaching your un-serialized object to a valid db connection.</p> <p>Without knowing what's inside your Template class (and what resources it uses and how) it's hard to guess what's wrong but I hope this is a good enough clue on where to start looking.</p> <p>To give you a better idea of what I'm talking about, consider this:</p> <h1>template.php</h1> <pre><code>&lt;?php class Template { function __construct($c) { $this-&gt;conn = $c; $this-&gt;foo = "bar"; } function get_data() { $result = mysql_query("select 1234 as test", $this-&gt;conn); $data = mysql_fetch_array($result); return $data; } function attach_db($c) { $this-&gt;conn = $c; } } ?&gt; </code></pre> <h1>first.php</h1> <pre><code>&lt;?php session_start(); require('template.php'); $conn = mysql_connect('localhost', 'root', ''); $template = new Template($conn); ?&gt; &lt;pre&gt; Your $template var, freshly created: &lt;?php var_dump($template); ?&gt; Accessing the resources: &lt;?php var_dump($template-&gt;get_data()); ?&gt; &lt;?php $_SESSION['template'] = serialize($template); ?&gt; &lt;/pre&gt; </code></pre> <h1>other.php</h1> <pre><code>&lt;?php session_start(); require('template.php'); $template = unserialize($_SESSION['template']); ?&gt; &lt;pre&gt; Unserialized $template: &lt;?php var_dump($template); ?&gt; (notice that $template-&gt;foo === "bar" so your session un/serialization is working correctly) Accessing the (now invalid) mysql resources: &lt;?php var_dump($template-&gt;get_data()); ?&gt; &lt;/pre&gt; </code></pre> <p>Calling first.php should give you this:</p> <blockquote> <p>Your $template var, freshly created:<br> object(Template)#1 (2) {<br> ["conn"]=><br> resource(3) of type (mysql link)<br> ["foo"]=><br> string(3) "bar"<br> } </p> <p>Accessing the resources:<br> array(2) {<br> [0]=><br> string(4) "1234"<br> ["test"]=><br> string(4) "1234"<br> } </p> </blockquote> <p>Calling others.php should result in:</p> <blockquote> <p>Unserialized $template:<br> object(Template)#1 (2) {<br> ["conn"]=><br> int(0)<br> ["foo"]=><br> string(3) "bar"<br> }<br> (notice that $template->foo === "bar" so your session un/serialization is working correctly) </p> <p>Accessing the (now invalid) mysql resources: </p> <p>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in template.php on line 9 </p> <p>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in template.php on line 10 </p> <p>bool(false) </p> </blockquote> <p>To solve that you can re-create the resources that cannot be un/serialized.<br> Like this:</p> <h1>solution.php</h1> <pre><code>&lt;?php session_start(); require('template.php'); $template = unserialize($_SESSION['template']); ?&gt; &lt;pre&gt; Unserialized $template: &lt;?php var_dump($template); ?&gt; Attaching a valid db connection: &lt;?php $conn = mysql_connect('localhost', 'root', ''); $template-&gt;attach_db($conn); var_dump($template); ?&gt; Accessing the resources: &lt;?php var_dump($template-&gt;get_data()); ?&gt; &lt;/pre&gt; </code></pre> <p>Now, calling solution.php after having called first.php should give you this:</p> <blockquote> <p>Unserialized $template:<br> object(Template)#1 (2) {<br> ["conn"]=><br> int(0)<br> ["foo"]=><br> string(3) "bar"<br> } </p> <p>Attaching a valid db connection:<br> object(Template)#1 (2) {<br> ["conn"]=><br> resource(3) of type (mysql link)<br> ["foo"]=><br> string(3) "bar"<br> } </p> <p>Accessing the resources:<br> array(2) {<br> [0]=><br> string(4) "1234"<br> ["test"]=><br> string(4) "1234"<br> } </p> </blockquote> <p>As I said, without knowing what your template class does, it's not possible to say for sure what's happening.. this is just one possibility ;) </p> <p>Good luck!</p>
 

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