【问题标题】:Call to undefined method mysqli_result::result() in Codeigniter [duplicate]在 Codeigniter 中调用未定义的方法 mysqli_result::result() [重复]
【发布时间】:2019-04-03 11:15:40
【问题描述】:

我已运行此code 以显示database 表中的所有columns。

    public function autorun()
  {
    $mysql_query = "show columns from store_accounts";
    $query = $this->db->simple_query($mysql_query);
    foreach ($query->result() as $row) {
      $column_name = $row->Field;
      echo $column_name; exit;
    }
  }

但它给了我这个错误。

调用未定义的方法 mysqli_result::result()

【问题讨论】:

  • simple_query 不会返回任何结果,它只会检查并返回 TRUE & FALSE\
  • 你需要使用 $this->db->query('YOUR QUERY HERE');得到结果
  • @M.Hemant $query = $this->db->query("显示来自 store_accounts 的列"); $mysql_query = $query->result();然后我在 foreach 中写 $mysql_query 但它显示一列

标签: php codeigniter


【解决方案1】:

试试这个,simple_query 只会根据你的查询返回真或假

public function autorun() {
        $mysql_query = "show columns from store_accounts";
        $query = $this->db->query($mysql_query);
        foreach ($query->result() as $row) {
            $column_name = $row->Field;
            echo $column_name.'<p>';
        }
        die;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-03
    • 2020-01-19
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多