Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange output from $MYSQLi->fetch_row()
    text
    copied!<p>Here is the MYSQLi code:</p> <pre><code> public function display() { $sql = "SELECT title, date_posted, text, url FROM notes ORDER BY date_posted DESC LIMIT ?, ?"; $results = $this-&gt;query($sql, "ii", $this-&gt;page_offset, $this-&gt;notes_per_page); $results = $this-&gt;db-&gt;store_result(); while ($row = $results-&gt;fetch_row()) { var_dump($row); } //$this-&gt;write($results); } // this is the $this-&gt;db-&gt;query() function referred to above. public function query() { $args = func_get_args(); $statement = $this-&gt;db-&gt;prepare($args[0]); $args = array_slice($args, 1); call_user_func_array(array($statement, 'bind_param'), &amp;$args); $statement-&gt;execute(); return $statement; } </code></pre> <p>The MYSQL table:</p> <pre><code>mysql&gt; desc notes; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | date_posted | date | NO | | NULL | | | title | varchar(255) | NO | | NULL | | | text | longblob | NO | | NULL | | | url | varchar(255) | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ </code></pre> <p>A sample row:</p> <pre><code>mysql&gt; SELECT title, url, date_posted FROM notes WHERE url='init'; +-------+------+-------------+ | title | url | date_posted | +-------+------+-------------+ | init | init | 2011-02-16 | +-------+------+-------------+ 1 row in set (0.00 sec) </code></pre> <p>The output for the corresponding row. What in the world...?:</p> <blockquote> <p>array(4) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(4) "init" [3]=> string(4) "�" }</p> </blockquote> <p>If I switch <code>fetch_array()</code> to <code>fetch_object()</code>, I get this:</p> <blockquote> <p>object(stdClass)#3 (4) { ["title"]=> string(0) "" ["date_posted"]=> string(0) "" ["text"]=> string(4) "init" ["url"]=> string(4) "�" }</p> </blockquote> <p>Thank you for all and any help/suggestions/comments!</p> <p><strong>New observation:</strong></p> <p>Adding another column to the query outputs a new column (the wrong one again though). So for example, if:</p> <pre><code>// and yes, I do realize that I am repeating 'url', // and I have no clue why this is happening. $sql = "SELECT title, date_posted, text, url, url FROM notes ORDER BY date_posted DESC LIMIT ?, ?"; </code></pre> <p>Then the output row is:</p> <blockquote> <p>array(5) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(4) "init" [3]=> string(4) "�" [4]=> string(350) "</p> <p>This is the text for the init article. I cut it short for the sake of brevity in this stackoverflow question " }</p> </blockquote>
 

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