Note that there are some explanatory texts on larger screens.

plurals
  1. POvar_dump of result gives null value. But deeper inspection returns a integer
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/9302335/new-mysqli-object-is-null">New Mysqli Object is Null</a> </p> </blockquote> <p>I just started with building my database class for my MVC framework. While building this I am experimenting with simple queries and tables in order to make it work properly.</p> <p>I was trying to query the following:</p> <blockquote> <p>SELECT * FROM mvc_test</p> </blockquote> <p>This should return 3 rows:</p> <blockquote> <p>1 | test</p> <p>2 | test2</p> <p>3 | test3</p> </blockquote> <p>I use the following method to query:</p> <pre><code>&lt;?php $this-&gt;result = $this-&gt;conn-&gt;query($this-&gt;q); ?&gt; </code></pre> <p>Where $this->conn is:</p> <pre><code>&lt;?php $this-&gt;conn = new mysqli($this-&gt;reg-&gt;conf-&gt;database['host'], $this-&gt;reg-&gt;conf-&gt;database['user'], $this-&gt;reg-&gt;conf-&gt;database['password'], $this-&gt;reg-&gt;conf-&gt;database['database']); ?&gt; </code></pre> <p>Where $this->reg->conf->database contains all the values for host, database etc. This works, I have a connection.</p> <p>Now, when I var_dump the result like this:</p> <pre><code>&lt;?php var_dump($this-&gt;result); ?&gt; </code></pre> <p>I get this:</p> <blockquote> <p>object(mysqli_result)[9]</p> <p>public 'current_field' => null</p> <p>public 'field_count' => null</p> <p>public 'lengths' => null</p> <p>public 'num_rows' => null</p> <p>public 'type' => null</p> </blockquote> <p>But, as said before it should contain at least 3 rows, so I would expect num_rows to be '3'.</p> <p>Now, when I var_dump the num_rows of the result like this:</p> <pre><code>&lt;?php var_dump($this-&gt;result-&gt;num_rows); ?&gt; </code></pre> <p>I get a 'int 3' as response.</p> <p>Conclusion: in the first var_dump it's null, but with a deeper inspection I get a 3. So it reads 3 rows. When I add another row (the 4th), it returns a 4 as expected.</p> <p>My question is: why is the var_dump not working properly? Why Does it say null at first, but with a deeper inspection it does have a value.</p> <p>Thanks in advance, I'm really struggling with this one since I don't get any errors as well.</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