mysqli只返回一行,而不是多行
我对mysqli只返回一行,而不是多行,mysql,mysqli,Mysql,Mysqli,我对mysqli完全是新手,我获取了生成的代码,并根据需要对其进行了调整 更新: public function getServeurByName($string) { $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where GSP_nom=?"); $this->throwExceptionOnError(); mysql
mysqli
完全是新手,我获取了生成的代码,并根据需要对其进行了调整
更新:
public function getServeurByName($string) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where GSP_nom=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 's', $string);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->idServ, $row->GSP_nom, $row->IPserv, $row->port, $row->tickrate, $row->membre, $row->nomPays, $row->finContrat, $row->actif, $row->timestamp, $row->type, $row->jeux, $row->slot, $row->ipClient, $row->essai, $row->reussite, $row->echec, $row->valide, $row->email);
while (mysqli_stmt_fetch($stmt)) {
$row->timestamp = new DateTime($row->timestamp);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->idServ, $row->GSP_nom, $row->IPserv, $row->port, $row->tickrate, $row->membre, $row->nomPays, $row->finContrat, $row->actif, $row->timestamp, $row->type, $row->jeux, $row->slot, $row->ipClient, $row->essai, $row->reussite, $row->echec, $row->valide, $row->email);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
问题出在这个示例中,我使用的模板只返回一行,而不是所有记录。
请问怎么修
编辑2:
print_r($row) show :
stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => )
/
打印(行);显示
我自己没有使用过mysqli,但对我来说,问题似乎就在这里:
if(mysqli_stmt_fetch($stmt)) {
$row->timestamp = new DateTime($row->timestamp);
return $row;
} else {
return null;
}
可能是这样的(不能保证不经修改就可以工作,而且它肯定会破坏您通过返回空数组而在0结果上返回null的约定。.根据您的需要进行调整):
如果您在$arr元素的内容方面遇到问题,这里的讨论可能会有所帮助:mysqli是只返回一行还是您的代码?是的,他返回的是数据库的第一行,仅此而已。获取一行“0”。我需要在哪里进行更改?感谢调试,我会打印($row);在while循环和打印中($arr);在返回之前,尝试从那里开始。我没有调试这个。如果你有什么想法,请告诉我,我被困在这里了?您可以用您迄今为止尝试和发现的内容更新您的问题。请参阅我的:更新1+更新2请所有信息都在那里;)非常感谢。我猜问题出在flex中,因为正确的值在$rows中
if(mysqli_stmt_fetch($stmt)) {
$row->timestamp = new DateTime($row->timestamp);
return $row;
} else {
return null;
}
$arr = array();
while (mysqli_stmt_fetch($stmt)) {
// copy data from $row to $arr
}
return $arr;