$ mysqli-> fetch_object($ result)不起作用 [英] $mysqli->fetch_object($result) not working

查看:46
本文介绍了$ mysqli-> fetch_object($ result)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习mysqli.

I am learning mysqli.

我正在尝试从"tbllogin"表中获取数据.

I am trying to fetch data from a table "tbllogin".

      //DATABASE CONNECTION

      $hostname="p:localhost";
      $database="dbLogin";
      $username="user1";
      $password="pwd1";



      $mysqli = new mysqli($hostname, $username, $password,$database);

      if(mysqli_connect_errno()){

       echo mysqli_connect_error();

      }

      // Create Query
      $query = "SELECT * FROM tbllogin";


      // Escape Query

      $query = $mysqli->real_escape_string($query);
      echo $query;

      // Execute Query

      if($result = $mysqli->query($query)){

          print_r($result);

          while($row = $mysqli->fetch_object($result)){

              echo $row->column;

          }

          //Free result set
          $result->close();

      }



      ?>

但是$mysqli->fetch_object($result)无法正常工作.包含$mysqli->fetch_object($result)if语句不执行.我无法确定是否有任何错误.

But $mysqli->fetch_object($result) is not working. The if statement containing $mysqli->fetch_object($result) does not execute. I cannot identify if there is any error.

请帮助. 另外,建议mysqli程序形式是更好的还是面向对象的形式?

Please help. Also, suggest whether mysqli procedural form is better or object-oriented form?

提前谢谢.

推荐答案

不是$result->fetch_object()吗?

http://php.net/manual/en/mysqli -result.fetch-object.php

从示例1:

if ($result = $mysqli->query($query)) {

    /* fetch object array */
    while ($obj = $result->fetch_object()) {
        printf ("%s (%s)\n", $obj->Name, $obj->CountryCode);
    }

根据此stackoverflow页面上的答案,两者之间没有太大区别这两个.

According to the answers on this stackoverflow page, there is not much of a difference between the two.

这篇关于$ mysqli-> fetch_object($ result)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆