PHP MySQL fetch_assoc выводит "0" в конце - PullRequest
0 голосов
/ 23 июня 2018

Здравствуйте, через некоторое время цикл 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']." ";
        }

    }

не работает. вывод (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();

}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...