Here is the MYSQLi code:
public function display() {
$sql = "SELECT title, date_posted, text, url
FROM notes ORDER BY date_posted DESC
LIMIT ?, ?";
$results = $this->query($sql, "ii",
$this->page_offset,
$this->notes_per_page);
$results = $this->db->store_result();
while ($row = $results->fetch_row()) {
var_dump($row);
}
//$this->write($results);
}
// this is the $this->db->query() function referred to above.
public function query() {
$args = func_get_args();
$statement = $this->db->prepare($args[0]);
$args = array_slice($args, 1);
call_user_func_array(array($statement, 'bind_param'), &$args);
$statement->execute();
return $statement;
}
The MYSQL table:
mysql> 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 | |
+-------------+--------------+------+-----+---------+----------------+
A sample row:
mysql> 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)
The output for the corresponding row. What in the world...?:
array(4) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(4) "init" [3]=> string(4) "�" }
If I switch fetch_array()
to fetch_object()
, I get this:
object(stdClass)#3 (4) { ["title"]=> string(0) "" ["date_posted"]=> string(0) "" ["text"]=> string(4) "init" ["url"]=> string(4) "�" }
Thank you for all and any help/suggestions/comments!
New observation:
Adding another column to the query outputs a new column (the wrong one again though). So for example, if:
// 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 ?, ?";
Then the output row is:
array(5) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(4) "init" [3]=> string(4) "�" [4]=> string(350) "
This is the text for the init article. I cut it short for the sake of brevity in this stackoverflow question " }