doujia4041 2016-12-10 16:20
浏览 42
已采纳

为foreach()PDO PHP提供的参数无效

I am trying to display data from a database, I do not quite understand all the processes that php follows to get and prepare information. The case is that it seems that I do not load what is in the variable $filas

Error: Warning: Invalid argument supplied for foreach() in /home/u571414187/public_html/systems/EazyFive/Controlador/cargar.php on line 20

Cargar.php

<?php

function cargar(){
    $consultas = new consultas();
    $filas = $consultas->cargarDatos;

    echo "<table>
            <tr>
                <th>ID</th>
                <th>Nombre</th>
                <th>Pass</th>
                <th>Canal</th>
                <th>Puntuacion</th>
                <th>url_img</th>
                <th>url_perfil</th>
                <th>logros</th>
            </tr>";

    foreach ($filas as $fila) {
        echo "<tr>";
        echo "<td>".$fila['id']."</td>";
        echo "<td>".$fila['user']."</td>";
        echo "<td>".$fila['pass']."</td>";
        echo "<td>".$fila['canal']."</td>";
        echo "<td>".$fila['puntuacion']."</td>";
        echo "<td>".$fila['url_img']."</td>";
        echo "<td>".$fila['url_perfil']."</td>";
        echo "<td>".$fila['logros']."</td>";
        echo "</tr>";
    }
    echo "</table>";
}
?>

class.consultas.php

<?php

class consultas{
    public function insertarProducto($arg_user, $arg_pass, $arg_canal, $arg_puntuacion, $arg_urlimg, $arg_urlperfil, $arg_logros){
        $modelo = new conexion();
        $conexion = $modelo->get_conexion();
        $sql = "insert into EzyFive_users (user, pass, canal, puntuacion, url_img, url_perfil, logros) values (:user, :pass, :canal, :puntuacion, :url_img, :url_perfil, :logros)";
        $statement = $conexion->prepare($sql);
        $statement->bindParam(':user', $arg_user);
        $statement->bindParam(':pass', $arg_pass);
        $statement->bindParam(':canal', $arg_canal);
        $statement->bindParam(':puntuacion', $arg_puntuacion);
        $statement->bindParam(':url_img', $arg_urlimg);
        $statement->bindParam(':url_perfil', $arg_urlperfil);
        $statement->bindParam(':logros', $arg_logros);  

        if(!statement){
            return "Error al crear el registro";
        }
        else{
            $statement->execute();
            return "Registro creado correctamente";
        }

    }

    public function cargarDatos(){
        $row = null;
        $modelo = new conexion();
        $conexion = $modelo->get_conexion();
        $sql = "select * from EzyFive_users";
        $statement = $conexion->prepare($sql);
        $statement->execute();
        while($resultado = $statement->fetch()){
            $rows[] = $result;
        }
        return $rows;
    }


}
?>

I have also tried to enter array in the foreach, and it did not indicate any error to me, but it did not show any information, everything in white And now if someone can explain me how to capture in error, perfect.

                </tr>";

    foreach ((array) $filas as $fila) {
        echo "<tr>";

Conexion.PHP

<?php

class conexion{
    public function get_conexion(){
        $user = "user";
        $pass = "pass";
        $host = "localhost";
        $db = "db";

        $conexion = new PDO("mysql:host=$host;dbname=$db;", $user, $pass);
        return $conexion;
    }
}
?>
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号