reactphp - Undefined index

Asked

Viewed 31 times

0

I’m Learning reactphp and when I try to pay back the data bank information of that mistake Undefined index I don’t know why

code q am using:

<?php

require 'vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$server = stream_socket_server('tcp://127.0.0.1:8080');
stream_set_blocking($server, false);

$loop->addTimer(0.8, function () {
    include 'conect.php';
    $sql = "SELECT  `Msn` FROM `tss`";
    $execut=mysqli_query($link,$sql);
    while($row = mysqli_fetch_row($execut)){
        $msn = $row['Msn'];
        echo $msn . PHP_EOL;
        echo "<br>";
    }
});

$loop->addTimer(0.3, function () {
    include 'conect.php';
    $sql1 = "SELECT  `Usuario` FROM `tss`";
    $exe =mysqli_query($link,$sql1);
    while($row = mysqli_fetch_row($exe)){
        $usu=$row['Usuario'];
        echo $usu;
    }

});

$loop->run();
?>

connection to the seat:

<?php
$host ="localhost";
$usu="root";
$senha="";
$bd="ts";

$link = mysqli_connect($host, $usu, $senha, $bd);

if (!$link) {
    echo "Error: Falha ao conectar-se com o banco de dados MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

?>

inserir a descrição da imagem aqui

  • Have you checked the value of $row? What is?

  • @Andersoncarloswoss, $row['Msn'] that comes from the column Msn, she has the die that was to bring that would TESTE

  • Emphasis on "was to bring". The question is, did you check if the value came?

  • @Andersoncarloswoss giving a var_export($row) he comes back array ( 0 => 'TESTE',) I could be wrong but he was supposed to come back 0=>'Teste' and yes Msn=>'Teste would you explain to me why he’s coming back 0

1 answer

1


The reason for the mistake is that you’re putting mysqli_fetch_row and the right and mysqli_fetch_array then I’d be like this

<?php

require 'vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$server = stream_socket_server('tcp://127.0.0.1:8080');
stream_set_blocking($server, false);

$loop->addTimer(0.8, function () {
    include 'conect.php';
    $sql = "SELECT  `Msn` FROM `tss`";
    $execut=mysqli_query($link,$sql);
    while($row = mysqli_fetch_array($execut)){
        $msn = $row['Msn'];
        echo $msn . PHP_EOL;
        echo "<br>";
    }
});

$loop->addTimer(0.3, function () {
    include 'conect.php';
    $sql1 = "SELECT  `Usuario` FROM `tss`";
    $exe =mysqli_query($link,$sql1);
    while($row = mysqli_fetch_array($exe)){
        $usu=$row['Usuario'];
        echo $usu;
    }

});

$loop->run();
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.