fetch_assoc循环一段时间后,PHP会在末尾显示“ 0”。
我的代码:
public function handle()
{
$conn = mysqli_connect("***********","***********","************","********");
if($conn->connect_errno){
printf("Connection failed!", $conn->connect_error);
exit();
} else {
$result = $conn->query("select * from VoiceJoin order by VoiceJoinID desc limit 5");
}
while($row = $result->fetch_assoc()){
echo $row['UserName']." ";
}
$conn->close();
}
我也尝试过:
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo $row['UserName']." ";
}
}
不起作用。 output (img)
谢谢!
我的php文件中的代码
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class getLatestVoiceJoin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'get:latest:voice:join';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get the 5 latest VoiceJoin';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$conn = mysqli_connect("*","*","*","*");
if($conn->connect_errno){
printf("Connection failed!", $conn->connect_error);
exit();
} else {
$result = $conn->query("select * from VoiceJoin order by VoiceJoinID desc limit 5");
}
while($row = $result->fetch_assoc()){
echo $row['UserName']."-";
}
$conn->close();
}
}