私のphp環境には奇妙な問題があります:
次のコード:
public static function getAllVotesOfGroup($groupid){
$con = new \SYSTEM\DB\Connection(new \DBD\uVote());
$res = $con->prepare( 'selVoteByGrp',
'SELECT * FROM `uvote_votes` WHERE `group` = ?;',
array($groupid));
$result = array();
//$r = array();
while($r = $res->next()){
//print_r($r);
$result[] = $r;
print_r($result);
echo "</br></br>";
}
//print_r($result);
return $result;
}
public function next($object = false, $result_type = MYSQL_BOTH){
if($object){
$this->current = mysqli_fetch_object($this->res);
} else {
$this->current = mysqli_fetch_assoc($this->res);
}
return $this->current;
}
私の他のマシンでは、このコードは私が望むすべての値を返しますが、このマシンはこれを返します: -> getAllVotesOfGroup(1) からのコードをエコー
Array ( [0] => Array ( [ID] => 1 [group] => 1 [title] => Test [text] => Testabstimmung [time_start] => 2013-06-12 [time_end] => 2015-06-13 ) )
Array ( [0] => Array ( [ID] => 2 [group] => 1 [title] => Test2 [text] => Testabstimmung [time_start] => 2014-06-13 [time_end] => 2012-06-16 ) [1] => Array ( [ID] => 2 [group] => 1 [title] => Test2 [text] => Testabstimmung [time_start] => 2014-06-13 [time_end] => 2012-06-16 ) )
Array ( [0] => Array ( [ID] => 3 [group] => 1 [title] => Test3 [text] => bla [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) [1] => Array ( [ID] => 3 [group] => 1 [title] => Test3 [text] => bla [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) [2] => Array ( [ID] => 3 [group] => 1 [title] => Test3 [text] => bla [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) )
Array ( [0] => Array ( [ID] => 4 [group] => 1 [title] => Test4 [text] => blub [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) [1] => Array ( [ID] => 4 [group] => 1 [title] => Test4 [text] => blub [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) [2] => Array ( [ID] => 4 [group] => 1 [title] => Test4 [text] => blub [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) [3] => Array ( [ID] => 4 [group] => 1 [title] => Test4 [text] => blub [time_start] => 0000-00-00 [time_end] => 0000-00-00 ) )
ご覧のとおり、おそらく $r が参照であり、実際の値ではなく参照のみが配列に追加されるため、以前の値が置き換えられます。
何故ですか?その動作を変更するためにいくつかのphp.iniオプションを設定できますか?
追加:これはうまくいきます!しかし、私が欲しいものではありません;-)
$result = array();
while($r = $res->next()){
$result[] = array('title' => $r['title'],'text' => $r['text']);
}
return $result;
OK、私はそれを解決することができました;-)
http://www.php.net/manual/en/mysqli-stmt.fetch.php#83284を参照してください。
問題は、データではなく参照を返す mysqli-stmt-fetch im を使用することです。