I am using the following code to return a resultset from a prepared statement in mysqli.
$sql = 'SELECT L.LABEL_ID, L.LABEL_NAME, L.PARENT_ID, L.BREADCRUMB
FROM LG_RP_LABELS L
JOIN LG_RP_ARTICLE_LABELS A
ON L.LABEL_ID = A.LABEL_ID
WHERE A.ARTICLE_ID = ?';
try {
$dbh = new DbMySql();
$stmt = $dbh->prepare($sql);
$stmt->bind_param('i', $this->articleId);
$stmt->bind_result($row['LABEL_ID'],
$row['LABEL_NAME'],
$row['PARENT_ID'],
$row['BREADCRUMB']);
$stmt->execute();
$count = 0;
while ($stmt->fetch()) {
$this->articleLabels[$count] = $row;
$count++;
}
$stmt->free_result();
$dbh->close();
} catch (DbConnectException $e) {
die ($e->getFormattedException());
} catch (SqlException $e) {
die ($e->getFormattedException());
}
The problem is that if I loop over $this->articleLabels, every entry in the array is the same as the last fetch(). Which tells me it is not passing by value, but rather by reference and the pointer is just being moved with each fetch() call.
How do I get the actual values out of the fetch() call and not the reference?